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`);



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 发布文章使用:只允许注册用户才可以访问!


js console 性能测试 & don't-use-array-foreach-use-for-instead的更多相关文章

  1. 为什么 array.foreach 不支持 async/await

    一.背景 react 项目中,渲染组件时,显示的数据一直有问题,本来以为是 react 组件的问题,后来才发现罪魁祸首在 fetch 数据的过程,因为我用了 async/await ,而却搭配了 fo ...

  2. JS中的 map, filter, some, every, forEach, for in, for of 用法总结和区别

    JS中的 map, filter, some, every, forEach, for in, for of 用法总结和区别  :https://blog.csdn.net/hyupeng1006/a ...

  3. js中数组的循环与遍历forEach,map

    对于前端的循环遍历我们知道有 针对js数组的forEach().map().filter().reduce()方法 针对js对象的for/in语句(for/in也能遍历数组,但不推荐) 针对jq数组/ ...

  4. 总结JS中string、math、array的常用的方法

    JS为每种数据类型都内置很多方法,真的不好记忆,而且有些还容易记混,现整理如下,以便以后查看: 一.String ①charAt()方法用于返回指定索引处的字符.返回的字符是长度为 1 的字符串. 语 ...

  5. Array.forEach原理,仿造一个类似功能

    Array.forEach原理,仿造一个类似功能 array.forEach // 设一个arr数组 let arr = [12,45,78,165,68,124]; let sum = 0; // ...

  6. 如何在 Array.forEach 中正确使用 Async

    本文译自How to use async functions with Array.forEach in Javascript - Tamás Sallai. 0. 如何异步遍历元素 在第一篇文章中, ...

  7. postgresql:array & foreach

    --数组: SELECT (ARRAY['{101, 111, 121}', '{201, 211, 221}'])[1]::text[]; SELECT (ARRAY['{101, 111, 121 ...

  8. js console API All In One

    js console API All In One const log = console.log; for(const key in console) { log(`navigator.${key} ...

  9. js console.log all in one

    js console.log all in one this & arguments "use strict"; /** * * @author xgqfrms * @li ...

随机推荐

  1. 前端面试之JavaScript的基本数据类型!

    前端面试之JavaScript的基本数据类型! JS的基本数据类型 数字 字符串 布尔值 JavaScript中有两个特殊的原始值: null (空) 和undefined (未定义), , 它们不是 ...

  2. kotlin和python哪个好!程序员怎样优雅度过35岁中年危机?满满干货指导

    导语 学历永远是横在我们进人大厂的一道门槛,好像无论怎么努力,总能被那些985,211 按在地上摩擦! 不仅要被"他们"看不起,在HR挑选简历,学历这块就直接被刷下去了,连证明自己 ...

  3. mybatis框架整合及逆向工程

    mybatis框架整合及逆向工程 一.三大框架整合 ​ 整合SSM框架 1.导入pom文件 1.导入spring的pom依赖 <?xml version="1.0" enco ...

  4. git的使用学习笔记---分支删除

    一.使用场景: 1.修改bug,原来分支不管用 2,分支太多不易管理 二.方法 git branch -d branch1 无法删除:原因在与该分支为目前工作的分支,所以要切换分支 git check ...

  5. java中List元素移除元素的那些坑

    https://blog.csdn.net/javageektech/article/details/96668890  List  的迭代器类 采用倒序移除 jdk1.8的写法 public sta ...

  6. dij的优先队列边表优化

    dij的复杂度为v*v,通过优先队列优化后为e*logv. (第一次写,没有过多的测试,不保证对.只当是测试blog了!) #include<cstdio> #include<ios ...

  7. LOJ10082

    题目描述 原题来自:Centrual Europe 2005 我们有N个字符串,每个字符串都是由 a 至 z 的小写英文字母组成的.如果字符串A的结尾两个字符刚好与字符串B的开头两个字符匹配,那么我们 ...

  8. MD5、sha加密

    MD5: 不可逆,一般用于密码的加密存储,数字签名,文件完整性验证 MD5码具有高度离散性,不可预测 MD5长度为128位,重复率几乎为0 易受密码分析的攻击 Sha: 对于长度小于2^64位的消息, ...

  9. CS229 Lecture 01

    CS229 Lecture notes 01 机器学习课程主要分为4部分:监督学习:学习理论:无监督学习:增强学习. $x^{(i)}$表示特征,$y^{(i)}$表示目标,$i=1...m$.m是训 ...

  10. 基于efcore的分表组件开源

    ShardingCore ShardingCore 是一个支持efcore 2.x 3.x 5.x的一个对于数据库分表的一个简易扩展, 目前该库暂未支持分库(未来会支持),仅支持分表,该项目的理念是让 ...