javascript 有没有办法限制javascript性能来模拟慢速客户端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8521683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:42:01  来源:igfitidea点击:

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

javascript

提问by Addsy

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.

我正在一个使用 jQuery 的网站上工作,并且有相当数量的 javascript 使用$(document).ready(). 在我的开发机器上,一切运行良好,但它是一台非常强大的机器。我收到过使用旧硬件的人的报告,这些行为看起来很奇怪,我相当确信这取决于在较慢的机器上处理这个初始 javascript 所花费的时间。

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?

显然,解决方案是整理这个初始的 javascript,但它让我想知道 - 有没有人知道一种方法可以在 Chrome 或 Firefox 中降低 javascript 的执行速度,以便能够在我的开发机器上模拟这些较慢的客户端?

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

更新:在发布此问题时,没有与今天相同的一组工具。当时 VM 选项是最佳选择,因此我将其保留为已接受的答案。但是,这些天我会按照 Oded Niv 的建议直接使用 Chrome 开发工具

采纳答案by isJustMe

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

这可能不是最好的解决方案,但绝对可行的是运行虚拟机,您可以在那里指定所有硬件规格,只要它们低于您的真实机器即可。看看这个帖子

回答by Oded Niv

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

Chrome developer tools -> Timeline您现在可以选择降低 CPU 的速度,查找下拉列表:

Chrome CPU throttling

Chrome CPU 节流

UPDATE:

更新:

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

Chrome(ium) 在新版本中发生了变化,它现在位于Performance选项卡下,您必须单击角落的设置按钮才能显示此功能:

Chrome new CPU throttling

Chrome 新的 CPU 节流

回答by gavaletz

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

我会使用虚拟机,只是限制它的资源。如果您不喜欢虚拟机,那么我会在院子里、旧货店等处找到一台旧机器,并将其用作测试平台。你永远无法修补它,用蹩脚的恶意软件程序填充它,然后它就会像“普通用户”的体验一样。:-)

回答by SLaks

Run Folding@Homein the background to eat up the CPU.

在后台运行Folding@Home以消耗 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.

如果你有一个多核处理器,使用任务管理器将 IE 限制为单核,也许还可以将一些 CPU 密集型应用程序限制为同一核。

回答by techfoobar

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://moslo.info/

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

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

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

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

回答by Nick Shvelidze

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

虚拟化就是答案!您可以使用 VirtualBox,它是免费的。你可以用它模拟一台速度较慢的机器

回答by Vladislav Kostenko

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.

您还可以尝试通过操作系统中的电源管理设置来降低 CPU。例如,对于 Win 8,您可以转到“控制面板\系统和安全性\电源管理\更改电源方案->更改高级电源设置->CPU 电源管理->最大 CPU 频率级别”之类的内容(抱歉,这是翻译来自非英文的 Win8 UI,但我认为不难找到设置)。这在某种程度上有所帮助。

回答by Jage

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.

我做了这个,不到一分钟,我的 Firefox 就吸收了我所有的记忆。您可以通过将 setTimeout() 更改为更高的值来缓慢地减慢过载。几乎使一切运行缓慢,切换选项卡和其他页面也加载。

<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>

回答by Mark Lutton

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.

我不知道您可以依赖或控制什么,但是您可以尝试安装两个防病毒程序(或至少与您拥有的 CPU 内核数量一样多),对每个程序进行全面扫描并使用这些全面扫描进行测试跑步。

回答by GSK

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

使用 Fiddler - 它是免费的 - 允许您模拟连接速度。拨号、ADSL 等

http://www.telerik.com/fiddler

http://www.telerik.com/fiddler