如何使用settimeout/setInterval的CPU效率来计算移动浏览器?
function fn() {
var start = new Date();
setInterval(function () {
var _s = new Date();
console.info(_s - start);
start = _s;
}, 1000/60)
}
fn()
您可以使用控制台:
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);