js performance.now vs console.time and console.timeEnd All In One
js 高精度时间戳
性能优化
性能测试
// const arr = (new Uint8Array(100000)).map((item, i) => i + 1);
const arr = (new Uint32Array(100000)).map((item, i) => i + 1);
// arr.length;
// 100000
// arr;
function testPerformance(arr, i) {
let startTime = performance.now();
console.log(`arr[i], i =`, arr[i], i);
let endTime = performance.now();
console.log(`performance time is \`${endTime - startTime}\` ms`);
}
function testTime(arr, i) {
console.time('array test');
console.log(`arr[i], i =`, arr[i], i);
console.timeEnd('array test');
// console.log(`performance time is \`${endTime - startTime}\` ms`);
}
setTimeout(() => {
testPerformance(arr, 0);
testPerformance(arr, 99999);
console.log('\n');
testTime(arr, 0);
testTime(arr, 99999);
}, 0);
// testPerformance(arr, 0);
// testPerformance(arr, 99999);
// console.log('\n');
// testTime(arr, 0);
// testTime(arr, 99999);
refs
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
https://developer.mozilla.org/en-US/docs/Web/API/console/time
https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd
https://nodejs.org/api/perf_hooks.html#perf_hooks_class_performance
https://nodejs.org/api/console.html#console_console_timeend_label
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 ️,侵权必究⚠️!