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. 在vSphere中为不同服务器配置IPMI功能

    在vSphere HA中如果要配置并启用DPM功能,需要记录服务器远程管理接口的IP地址(不是ESXi的IP地址,而是另一个独立的IP地址,是与ESXi服务器同一网段的另一个IP地址)与MAC地址.远 ...

  2. 防sql注入之参数绑定 SQL Injection Attacks and Defense 预处理语句与存储过程

    http://php.net/manual/zh/pdo.prepared-statements.php 预处理语句与存储过程 很多更成熟的数据库都支持预处理语句的概念.什么是预处理语句?可以把它看作 ...

  3. httpd反向代理实践(二)

    div.example { background-color: rgba(229, 236, 243, 1); color: rgba(0, 0, 0, 1); padding: 0.5em; mar ...

  4. 基于Koa2框架的项目搭建及实战开发

    Koa是基于 Node.js 平台的下一代 web 开发框架,由express原班人马打造,致力于成为一个更小.更富有表现力.更健壮的 Web 框架.使用 koa 编写 web 应用,通过组合不同的 ...

  5. JavaWeb——EL及JSTL学习总结

    什么是EL表达式 为什么需要EL EL的主要作用 EL的语法 EL的开发步骤 EL实例练习 EL中的运算符 EL表达式显示内容的特点 EL的特点 EL隐式对象 EL隐式对象介绍 隐式对象实例练习 什么 ...

  6. centos6.5安装KVM,并在KVM中安装虚拟6.5系统

    =============================环境搭建================================================== 1.检查CPU信息 KVM 需要 ...

  7. P4254 [JSOI2008]Blue Mary开公司 (李超树)

    题意:插入一些一次函数线段 每次询问在x = x0处这些线段的最大值 题解:李超树模版题 维护优势线段 注意这题的输入是x=1时的b #include <iostream> #includ ...

  8. Grakn Forces 2020

    比赛链接:https://codeforces.com/contest/1408 A. Circle Coloring 题意 给出三个长为 $n$ 的序列 $a,b,c$,对于每个 $i$,$a_i ...

  9. zoj2112 Dynamic Rankings (主席树 || 树套树)

    The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...

  10. 洛谷 P1429 平面最近点对(加强版) (分治模板题)

    题意:有\(n\)个点对,找到它们之间的最短距离. 题解:我们先对所有点对以\(x\)的大小进行排序,然后分治,每次左右二等分递归下去,当\(l+1=r\)的时候,我们计算一下距离直接返回给上一层,若 ...