xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js console 性能测试 & don't-use-array-foreach-use-for-instead

don't-use-array-foreach-use-for-instead

slower

https://coderwall.com/p/kvzbpa/don-t-use-array-foreach-use-for-instead

https://jsperf.com/fast-array-foreach

// OK
console.time(`for 计时器`);
console.timeEnd(`for 计时器`);

// Bad
console.time(`for 计时器 begin`);
console.timeEnd(`for 计时器 end`);

image

image



console.time(`for 计时器`);
for (let i = 0; i < 10000; i++) {
    let result = i ** 3;
    console.log(`result = ${result}`);
}
console.timeEnd(`for 计时器`);
// for 计时器: 1744.241943359375ms




const a = [];
for (let i = 0; i < 10000; i++) {
    a[i] = i;
}
console.time(`forEach 计时器`);
a.forEach((i) => {
    let result = i ** 3;
    console.log(`result = ${result}`);
})
console.timeEnd(`forEach 计时器`);
// forEach 计时器: 2139.04296875ms

js console 性能测试

https://yq.aliyun.com/ziliao/174827
http://www.cnblogs.com/cilong/articles/1845282.html
https://www.javascriptcn.com/read-2807.html
http://www.jb51.net/article/64971.htm



/* 



console.trace()用来追踪函数的调用过程。

对于前端开发人员,在开发过程中经常需要监控某些表达式或变量的值,如果使用用 debugger 会显得过于笨重,最常用的方法是会将值输出到控制台上方便调试。


console.table(people);


console.time()和console.timeEnd()

console.time('计时器');
for (var i = 0; i < 1000; i++) {
    for (var j = 0; j < 1000; j++) {}
}
console.timeEnd('计时器');



console.profile()
借助控制台以及console.profile()方法我们可以很方便地监控运行性能。

console.profile('性能分析');
// parent();
console.profileEnd();

*/

attributes

https://developer.mozilla.org/en-US/docs/Web/API/Element/attributes

https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttributes

https://developer.mozilla.org/en-US/docs/Web/API/Element/hasAttribute


Uint8Array


let arr = new Uint8Array(10).map((item, i) => item = i);
// Uint8Array(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

let arr = new Uint8Array(10).map((item, i) => item = i + 1);
// Uint8Array(10) [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2017-10-23 13:34  xgqfrms  阅读(77)  评论(3编辑  收藏  举报