Is there a way to throttle javascript performance to simulate a slow client

Javascript

Javascript Problem Overview


I am working on a site that uses jQuery and has a fair amount of javascript that is run using $(document).ready(). On my dev machine everything runs great but it's a pretty powerful machine. I have had reports from people using older hardware of behavior that seems strange and I am fairly convinced that it is down to the time taken to process this initial javascript on slower machines.

Clearly, the solution is to sort out this initial javascript but it got me wondering - does anyone know of a way to slow down the execution speed of javascript in either Chrome or Firefox to be able to simulate these slower clients on my dev machine?

Cheers!

Update: Back when this question was posted, there weren't the same set of tools that there are today. At that time the VM option was the best option therefore I am leaving it as the accepted answer. However these days I would go straight for Chrome dev tools instead as suggested by Oded Niv

Javascript Solutions


Solution 1 - Javascript

Under Chrome developer tools -> Timeline you now an option to throttle down the CPU, look for the dropdown:

Chrome CPU throttling

UPDATE:

Chrome(ium) changed in new versions, it is now under the Performance tab, and you have to click the settings button in the corner for this feature to show up:

Chrome new CPU throttling

Solution 2 - Javascript

This might not be the best solution, but something that could definetely work is to run a virtual machine, there you could specify all hardware specs as long as they are lower than you real machine. Look at this post

Solution 3 - Javascript

I would use a VM and just limit it's resources. If you are not a fan of virtual machines, then I would go find an old machine at a yard sale, thrift store etc. and use that as a testing platform. You can never patch it, fill it up with crappy malware laden programs and then it will be just like the experience for an "average user." :-)

Solution 4 - Javascript

Run Folding@Home in the background to eat up the CPU.

If you have a multi-core processor, use Task Manager to limit IE to a single core, and perhaps also limit some CPU-intensive applications to the same core.

Solution 5 - Javascript

Virtualisation is the answer! You may use VirtualBox, it's free. You can simulate a slower machine with it

Solution 6 - Javascript

Easier than a virtual machine i believe will be some kind of a tool that can slow down selected apps (in your case the browser process).

Well you can always try setting the priority of your browser process to the lowest value.

Additionally you can try one of these tools. They are basically meant for slowing down the system/specific-apps so old games can be played on new systems. Will probably fit your test case.

http://moslo.info/

http://www.reocities.com/kulhain/

http://www.sierrahelp.com/Utilities/SlowdownUtilities.html

Solution 7 - Javascript

You can also try to throttle down your CPU via Power management settings in your OS. For example for Win 8 you can go to something like "Control Panel\System and security\Power management\Change you power scheme->Change advanced power settings->CPU power management->Max CPU frequency level" (sorry, this is translation from non English Win8 UI, but I think it is not hard to find the settings). This helps in some degree.

Solution 8 - Javascript

I made this and within like a minute my firefox was sucking up all my memory. You could prolly slow the overload by changing the setTimeout() to something higher. Pretty much made everything run slow, switching tabs and other page loads too.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
	body, html{
    	height:100%; 
    }

</style>
<script language="javascript" type="text/javascript">

var NUM = 0;
function addMore(){
	var cur = document.getElementById('ta').value;
	var newVal = NUM.toString();
	if(cur){
		newVal = newVal+cur;
	}
	NUM++;
	document.getElementById('ta').value = newVal;
	setTimeout("addMore()",1);
}

</script>
</head>

<body onload="addMore()">

<textarea id="ta" style="width:80%; height:80%;">0</textarea>

</body>
</html>

Solution 9 - Javascript

I don't know of anything you can depend on or control, but you might try installing two antivirus programs (or at least as many as the number of CPU cores you have), starting a full scan on each and testing with those full scans running.

Solution 10 - Javascript

Use Fiddler - its free - allows you to simulate the connection speed. dialup, ADSL etc.

http://www.telerik.com/fiddler

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAddsyView Question on Stackoverflow
Solution 1 - JavascriptOded NivView Answer on Stackoverflow
Solution 2 - JavascriptisJustMeView Answer on Stackoverflow
Solution 3 - JavascriptgavaletzView Answer on Stackoverflow
Solution 4 - JavascriptSLaksView Answer on Stackoverflow
Solution 5 - JavascriptNick ShvelidzeView Answer on Stackoverflow
Solution 6 - JavascripttechfoobarView Answer on Stackoverflow
Solution 7 - JavascriptVladislav KostenkoView Answer on Stackoverflow
Solution 8 - JavascriptJageView Answer on Stackoverflow
Solution 9 - JavascriptMark LuttonView Answer on Stackoverflow
Solution 10 - JavascriptGSKView Answer on Stackoverflow