当前位置:网站首页>js数组复制速度测试220320
js数组复制速度测试220320
2022-07-27 20:51:00 【kfepiza】
js数组复制速度测试220320
执行600000次
用 srcAr.concat() 用时 16 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 srcAr.slice() 用时 17 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 Array.from(srcAr) 用时 17 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 […srcAr] 用时 12 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 Object.assign([],srcAr) 用时 1985 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 JSON.parse(JSON.stringify(srcAr)) 用时 549 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
第二次用 srcAr.slice() 用时 16 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
第二次用 srcAr.concat() 用时 15 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 newAr=new Array(); for(let i=0;i43 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 newAr=new Array(); for(let i=0;i36 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 newAr=[]; for(let i=0;i32 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 newAr=[]; for(let i=0;i33 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 newAr=Array(srcAr.length); for(let i=0;i17 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
用 newAr=new Array(srcAr.length); for(let i=0;i23 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
第三次用 srcAr.concat() 用时 9 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
第三次用 srcAr.slice() 用时 14 毫秒
newAr=[0,1,2,3,4,5,6,7,8,9,十,十一,十二,十三,十四,十五]
测试代码
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"/><title></title><style>
#BodyH{
display:flex; align-items:center; justify-content:center;}
</style><script>
const ge=window.dgebi=function(e,s){
if(e&&e.constructor===String){
let n=e;e=document.getElementById(e);e=e||document.querySelector(n);}if(e&&s){
e.newE=e.newChild=s;e.appendChild(s);}return e;},
dcept=(p,tn="DIV")=>{
let e=document.createElement(tn);e.idfine=(i)=>{
e.id=i;return window[i]=e;};e.htm=(h)=>{
e.innerHTML=h;return e;};dgebi(p,e);return e;} ;
if(!document.title.length)(function(){
var str=document.URL; str=str.substring( str.lastIndexOf("/")+1 , str.length-5); str=decodeURI(str); document.title=str;})();
window.dwbr=function(a0=1){
let ar=arguments,br=dwbr.br; if(Number.isFinite(a0)){
br(a0);return;} for(let a of ar)document.write(a.replace(/\n/g,"<br/>"));br();}; dwbr.br=function(n=1){
for(let c=0;c<n;c++)document.write("<br/>");};
window.childIdvar=function(q){
for(let p of document.querySelectorAll(q))for(let c of p.children)if(c.id&&c.id.length>0)window[c.id]=c;};
</script><script>
</script></head><body style="margin:0; font-size:16px; "><header id="BodyH">
<label style="font-size:3rem; "></label><script>{
let s=document.currentScript; let l=s.previousElementSibling; if(!l.innerHTML.length)l.innerHTML=document.title}</script>
</header><div id="BodyB">
<div id="d1" style="font-size:20px;"></div>
</div><footer id="BodyF"></footer><style id="LastStyleTag"></style><script>const BodyH=dgebi("BodyH") , BodyB=dgebi("BodyB") , BodyF=dgebi("BodyF") , LastStyleTag=dgebi("LastStyleTag") , LastStyleSheet=LastStyleTag.sheet;
let d1=dgebi("d1"); for(let t=0;t<60;t++)dcept(d1,"div");
{
let dc=d1.children;
let srcAr=[0,1,2,3,4,5,6,7,8,9,'十','十一','十二','十三','十四','十五'] , newAr=null , ms , ci=0 , count=600 * 1000;
function showNewAr(){
dc[ci++].innerHTML="newAr=["+newAr+"]<br/>";}
dc[ci++].innerText="执行"+count+"次";
ms=Date.now(); for(let t=0;t<count;t++){
newAr=srcAr.concat();} dc[ci++].innerHTML="用 srcAr.concat() 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=srcAr.slice();} dc[ci++].innerHTML="用 srcAr.slice() 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=Array.from(srcAr);} dc[ci++].innerHTML="用 Array.from(srcAr) 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=[...srcAr];} dc[ci++].innerHTML="用 [...srcAr] 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=Object.assign([],srcAr);} dc[ci++].innerHTML="用 Object.assign([],srcAr) 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=JSON.parse(JSON.stringify(srcAr));} dc[ci++].innerHTML="用 JSON.parse(JSON.stringify(srcAr)) 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=srcAr.slice();} dc[ci++].innerHTML="第二次用 srcAr.slice() 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=srcAr.concat();} dc[ci++].innerHTML="第二次用 srcAr.concat() 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=new Array(); for(let i=0;i<srcAr.length;i++)newAr.push(srcAr[i]); } dc[ci++].innerHTML="用 newAr=new Array(); for(let i=0;i<srcAr.length;i++)newAr.push(srcAr[i]); 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=new Array(); for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } dc[ci++].innerHTML="用 newAr=new Array(); for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=[]; for(let i=0;i<srcAr.length;i++)newAr.push(srcAr[i]); } dc[ci++].innerHTML="用 newAr=[]; for(let i=0;i<srcAr.length;i++)newAr.push(srcAr[i]); 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=[]; for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } dc[ci++].innerHTML="用 newAr=[]; for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=Array(srcAr.length); for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } dc[ci++].innerHTML="用 newAr=Array(srcAr.length); for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=new Array(srcAr.length); for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } dc[ci++].innerHTML="用 newAr=new Array(srcAr.length); for(let i=0;i<srcAr.length;i++)newAr[i]=srcAr[i]; } 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=srcAr.concat();} dc[ci++].innerHTML="第三次用 srcAr.concat() 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
ms=Date.now(); for(let t=0;t<count;t++){
newAr=srcAr.slice();} dc[ci++].innerHTML="第三次用 srcAr.slice() 用时 "+"<strong class='ms' >"+(Date.now()-ms)+"</strong>"+" 毫秒"; showNewAr();
}
</script></body></html>
边栏推荐
- Figure basic knowledge code
- VIM editor tutorial
- XML 外部实体 (XXE) 漏洞及其修复方法
- What technology is RPA process automation robot? How to realize office automation?
- 西门子PLC能否实时无线采集多处从站模拟量数据?
- 加速IGBT国产化!比亚迪半导体将独立上市,市值或达300亿元!
- 常用泰勒展开
- Solve 5g pain points, Meizu 17 smart 5g fast and stable technology release
- How do I shut down oracle?
- Pentium fast system call learning
猜你喜欢

Common Taylor expansion

Library management system based on SSM framework

Interviewer: I can't carry a backpack at all. Are you going by yourself or I'll give you a lift?

Record the errors about formatc in R language

iMeta | 国际标准刊号ISSN印刷版正式确认,双ISSN申请完成

NDK 系列(6):说一下注册 JNI 函数的方式和时机

一篇文章读懂人工神经网络
![[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code](/img/6a/92ace81b798810299a2fec0ce6ae70.png)
[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code

Reinforcement learning - pytorch realizes advantage actor critical (A2C)

NDK series (6): let's talk about the way and time to register JNI functions
随机推荐
采用汇顶屏下光学指纹方案,三星Galaxy A71 5G上市
How to quickly view the API properties and usage of the h.265 video player easyplayer?
Zabbix4.0 uses SNMP agent to monitor vcenter6.5
ZCMU--1720: 死亡如风,我要装逼
怎么使用xshell免费版
进程同步的方式有哪些?
华为鸿蒙 3 正式发布,这个安全功能解决了一大痛点
评价自动化测试优劣的隐性指标
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
Calling dht11/22 temperature and humidity sensor in Proteus simulation Arduino
MapReduce(三)
用3dmax做折扇的思路方法与步骤
Pentium快速系统调用学习
台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
NDK series (6): let's talk about the way and time to register JNI functions
加速IGBT国产化!比亚迪半导体将独立上市,市值或达300亿元!
四次挥手的Socket交互流程
2022/7/24-7/25
Pro multi store version system, versatile is it!
The wechat installation package has expanded 575 times in 11 years, and the up owner: "98% of the documents are garbage"; Apple App store was exposed to a large number of pornographic apps; Four techn