js测试性能的方法

Perfomance.now

const t0 = performance.now();
for (let i = 0; i < array.length; i++) 
{
    
    
  // some code
}
const t1 = performance.now();
console.log(t1 - t0, 'milliseconds');

Console.time

console.time('test');
for (let i = 0; i < array.length; i++) {
    
    
  // some code
}
console.timeEnd('test');

不同浏览器会有差异不过影响不大;6层for循环,配合arr的length为6就可以达到5s左右,比较明显

猜你喜欢

转载自blog.csdn.net/weixin_43706224/article/details/129204310