开发者

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

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 w开发者_运维技巧hen 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


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

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

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:

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


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


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." :-)


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.


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


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


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.


You can fake slow performance with javascript like below

const btn = document.getElementById('btn')
const btn2 = document.getElementById('btn2')
const para = document.getElementById('para')

      
btn.addEventListener('click', ()=> {
  let startTime = performance.now();
  while (performance.now() - startTime < 700) {
    // Do nothing for 700 ms to emulate extremely slow code
  }

  para.innerHTML = 'CONTENT'
})

btn2.addEventListener('click', ()=> {
  para.innerHTML = ''
})
<button id="btn">PRINT</button>
<p id="para"></p>
<button id="btn2">Clear to try again</button>


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>


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.


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

http://www.telerik.com/fiddler

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜