js 测试性能

console.time('querySelector');
for(var i=0; i<1000; i++){
document.querySelector('body');
}
console.timeEnd('querySelector');


console.time('getElementById');
for(var i=0; i<1000; i++){
document.getElementById('body');
}
console.timeEnd('getElementById');

结果:

 

 

 

还可以用profile性能检测:

var test = {
test1 : 1,
say : function(){
console.log('hello');
}
}
console.profile('test.say()');
test.say();
test.say();
test.say();
test.say();
test.say();
console.profileEnd('test.say()');

结果:

 

posted @ 2017-07-13 00:09  网络虫  阅读(553)  评论(0编辑  收藏  举报