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`);
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的更多相关文章
- 为什么 array.foreach 不支持 async/await
一.背景 react 项目中,渲染组件时,显示的数据一直有问题,本来以为是 react 组件的问题,后来才发现罪魁祸首在 fetch 数据的过程,因为我用了 async/await ,而却搭配了 fo ...
- 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 ...
- js中数组的循环与遍历forEach,map
对于前端的循环遍历我们知道有 针对js数组的forEach().map().filter().reduce()方法 针对js对象的for/in语句(for/in也能遍历数组,但不推荐) 针对jq数组/ ...
- 总结JS中string、math、array的常用的方法
JS为每种数据类型都内置很多方法,真的不好记忆,而且有些还容易记混,现整理如下,以便以后查看: 一.String ①charAt()方法用于返回指定索引处的字符.返回的字符是长度为 1 的字符串. 语 ...
- Array.forEach原理,仿造一个类似功能
Array.forEach原理,仿造一个类似功能 array.forEach // 设一个arr数组 let arr = [12,45,78,165,68,124]; let sum = 0; // ...
- 如何在 Array.forEach 中正确使用 Async
本文译自How to use async functions with Array.forEach in Javascript - Tamás Sallai. 0. 如何异步遍历元素 在第一篇文章中, ...
- postgresql:array & foreach
--数组: SELECT (ARRAY['{101, 111, 121}', '{201, 211, 221}'])[1]::text[]; SELECT (ARRAY['{101, 111, 121 ...
- js console API All In One
js console API All In One const log = console.log; for(const key in console) { log(`navigator.${key} ...
- js console.log all in one
js console.log all in one this & arguments "use strict"; /** * * @author xgqfrms * @li ...
随机推荐
- Jmeter如何录制APP客户端脚本
简单五步教大家Jmeter录制APP客户端脚本: Step1 右键单击该测试计划,选择"添加"-"线程组",添加一个线程组. Step2 为了录制客户端的操作, ...
- Centos 7 Rabbitmq 安装并开机启动
准备工作 安装wget yum install -y wget rabbitmq安装需要依赖erlang,erlang安装参考:https://www.cnblogs.com/swyy/p/11582 ...
- session和cookie自动登录机制
cookie的存储 cookie是浏览器支持的一种本地存储方式.以dict,键值对方式存储. {"sessionkey": "123"} 浏览器会自动对于它进行 ...
- TCMalloc源码学习(二)
替换libc中的malloc free 不同平台替换方式不同. 基于unix的系统上的glibc,使用了weak alias的方式替换.具体来说是因为这些入口函数都被定义成了weak symbols, ...
- Vue中双向数据绑定是如何实现的?
vue 双向数据绑定是通过 数据劫持 结合 发布订阅模式的方式来实现的, 也就是说数据和视图同步,数据发生变化,视图跟着变化,视图变化,数据也随之发生改变:核心:关于VUE双向数据绑定,其核心是 Ob ...
- 系列trick - bitmask
目录 系列trick - bitmask 拆位 位运算优化(点少的)图操作 位筛 系列trick - bitmask 拆位 主体思想:位之间不影响,把每一位拆开来考虑贡献,转化成非常容易考虑的 0/1 ...
- Integer的十进制转二,八,十六进制
1,toBinaryString(int i) 将i以二进制形式输出出来 2,toOctalString(int i)将i以八进制形式输出出来 3,toHexString(int i)将i以十六进制形 ...
- Win10安装CUDA 10.2
目录 一.安装VS2015 二.安装CUDA 10.2 2.1 安装前工作 2.2 CUDA 10.2下载安装过程 2.2.1 下载CUDA 10.2 2.2.1.1 官网下载地址 2.2.1.2 网 ...
- spark SQL (二) 聚合
聚合内置功能DataFrames提供共同聚合,例如count(),countDistinct(),avg(),max(),min(),等.虽然这些功能是专为DataFrames,spark SQL还拥 ...
- Kubernetes --(k8s)volume 数据管理
容器的磁盘的生命周期是短暂的,这就带来了许多问题:第一:当一个容器损坏了,kubelet会重启这个容器,但是数据会随着container的死亡而丢失:第二:当很多容器在同一Pod中运行的时候,经常需要 ...