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()');

结果:

 

相关文章:

  • 2021-06-03
  • 2021-05-30
  • 2022-01-13
  • 2021-12-27
  • 2021-08-15
  • 2021-12-29
  • 2021-05-06
猜你喜欢
  • 2022-12-23
  • 2021-04-26
  • 2021-06-14
  • 2021-12-16
  • 2021-10-11
  • 2022-02-28
  • 2021-09-19
相关资源
相似解决方案