2012-10-25 22 views
0

如何使用setTimeout/setInterval来计算手机浏览器的CPU效率?setTimeout/setInterval手机浏览器来计算CPU效率

function fn() { 
    var start = new Date(); 
    setInterval(function() { 
     var _s = new Date(); 
     console.info(_s - start); 
     start = _s; 
    }, 1000/60) 
} 
fn() 
+0

它与'css3'有什么关系? –

+0

可能重复(或至少相关):[是否有任何标准的移动设备的Web浏览器在线程睡眠?](http://stackoverflow.com/questions/10739835/are-there-any-standards-for-移动设备的网络浏览器功能于条件方面的线程sleepi) – Bergi

回答

1

您可以使用console.time:

function someFunction(){ 
    console.timeEnd('someFunction timer'); 
    //this function's code goes here... 
    console.time('someFunction timer'); 
} 

这会给你你的函数了执行时间。这是你需要的吗?

或者,也许这样?

var start = new Date().getTime(); 

//your code 
var end = new Date().getTime(); 
var time = end - start; 
alert('Execution time: ' + time);