如何使用Javascript测试用户的计算机的处理能力? [英] How can I test the user's computer's processing power using Javascript?
问题描述
我做了一个漂亮的CPU密集型网页,有很多CSS3和Javascript。我想使用Javascript来测试用户的计算机是否能够处理脚本。我认为一种可能的方法是运行一些CPU密集型脚本,并看看它花了多长时间。
I made a pretty CPU intensive webpage with lots of CSS3 and Javascript. I want to use Javascript to test if the user's computer is capable of handling the scripts. I think a possible method is to run some CPU intensive scripts and see how long it took. However, I don't know how to actually implement this.
这是网页: http://leojiang.me/ (3D多维数据集只能在webkit浏览器中查看)。
Here's the webpage: http://leojiang.me/ (3D cube only viewable in webkit browsers).
推荐答案
var StartTime = new Date().getTime();
BenchMarkTestFunction(); // render frame for example
var EndTime = new Date().getTime();
var ElapsedMilliseconds = EndTime - StartTime;
var AcceptableTime = 1000; // one second
var IsGoodPerformance = ElapsedMilliseconds < AcceptableTime; // some number being acceptable performace
if(!IsGoodPerformance) {
alert("Sorry your browser is not good enough to run this site - go somewhere else");
}
您可以通过测试您的网站在不同的浏览器/设备,并查看它的执行方式和ElapsedMilliseconds的值。
You can determine what the AcceptableTime should be by testing your site on different browsers/devices and seeing how it performs and what the value for ElapsedMilliseconds was.
这篇关于如何使用Javascript测试用户的计算机的处理能力?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!