js 测试性能

来源:互联网 发布:php输出99乘法表 编辑:程序博客网 时间:2024/06/06 04:34

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

结果:


0 0
原创粉丝点击