当前位置:网站首页>jsArray array copy method performance test 2207300823
jsArray array copy method performance test 2207300823
2022-07-30 13:22:00 【kfepiza】
jsArray数组复制方法性能测试2207300823
测试代码
<!DOCTYPE html><html lang="zh-CN"><head><meta charset="utf-8"/><title></title><style> body{
margin:0} #BodyH{
display:flex; align-items:center; justify-content:flex-start; background-image:linear-gradient(to right, red, orange, yellow, green, cyan, blue, purple);} </style><script> if(!document.title.length)(function(){
var str=document.URL; str=str.substring( str.lastIndexOf("/")+1 , str.lastIndexOf('.')); str=decodeURI(str); document.title=str;})(); let isLog=true;clog=function(){
if(isLog)for(let a of arguments)console.log(a);}; n09="0123456789"; lAZ="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; laz="abcdefghijklmnopqrstuvwxyz"; Z62=n09+lAZ+laz; Z62o={
};for(let i=0;i<Z62.length;i++)Z62o[Z62[i]]=i; const CTTT="Content-type"; rdmN=(u)=>parseInt(Math.random()*u); rdmV=(sa)=>sa[rdmN(sa.length)]; rdmS=(l=1,sample=Z62)=>{
let s='';for(let i=0;i<l;i++)s+=rdmV(sample);return s;}; z62=z62l=(l)=>rdmS(l); decFrZ62=(z)=>{
let a=Array.from(z).reverse(); let i=0; for(let j=0;j<a.length;j++)i+=Z62o[a[j]]*Math.pow(62,j);return i;}; z62Now=()=>{
let l=Date.now(),a=[]; while(l>62){
a.push(Z62[l%62]);l=parseInt(l/62);};a.push(Z62[l]);return a.reverse().join('');}; z62Id=(l)=>{
let s=z62Now(); if(l&&l>6){
l-=6;s+=z62(l);}return s;}; rdmRgb=()=>'rgb('+rdmN(256)+','+rdmN(256)+','+rdmN(256)+')'; rdmBgc=()=>"background-color:"+rdmRgb()+";"; isA=(x)=>x&&x.constructor===Array,isS=(x)=>x&&x.constructor===String,isF=(x)=>x&&x.constructor===Function,isO=(x)=>x&&x.constructor===Object,isJ=(x)=>isA(x)||isO(x),isM=(x)=>x&&x.constructor===Map; isE=(x,tn)=>{
let b=(x&&x instanceof HTMLElement); if(b&&tn)b=(x.tagName===tn.toUpperCase()); return b;}; isColl=(x)=>x&&isFinite(x.length)&&x.constructor!==String; isEnterEvent=(ev)=>ev&&(ev.which===13&&ev.keyCode===13&&ev.key==="Enter"&&ev.code==="Enter"); triggee=triggerElementEvent=触发元素的事件=(e,evn)=>{
e=dgebi(e);e.dispatchEvent(new Event(evn)); return e;}; z24ParseInt=(s)=>{
let ar=Array.from(s); let ar1=ar.filter((v)=>isFinite(v)); return parseInt(ar1.join(''));}; stringSeparator=(str,ss,hf)=>{
if(!ss||ss.length===0)return str; let ar=str.split(ss.shift()); if(isF(hf))hf(ar); ar=ar.map((s)=>stringSeparator(s,ss.slice())); return ar;}; //ge //dgebi const ge=window.dgebi=function(i,s){
if(!i)return;let e=i;if(isS(i)){
e=document.getElementById(i);if(!e)e=document.querySelector(i);} if(!s)return e; s=ge(s); if(isE(e)&&isE(s))e.appendChild(e.新娃=e.xw=s);else{
clog("↓↓↓",e,"父或子不是Element",s,"↑↑↑");}return e;}; dce=window.dcept=(p,tn="DIV")=>{
let e=document.createElement(tn);e.idefine=(i)=>{
e.id=i;return window[i]=e;};e.htm=(h)=>{
if(h!==undefined)e.innerHTML=h;return e;}; e.ass=e.aCssText=(s)=>{
if(s)e.style.cssText+=";"+s;return e;};e.cls=(c)=>{
if(c!==undefined)e.className+=" "+c;return e;}; e.ce=(a0,c2,h2)=>{
let ar; if(isS(a0))ar=a0.split("=->");else ar=a0; let t=ar[0].replace(/\s/g,''),h=ar[1],ct=ar[2],c=ar[3]; e.ceLast=dcept(e,t).htm(h).htm(h2).aCssText(ct).cls(c).cls(c2); if(isS(ar[4]))eval("const P=e,I=e.ceLast;"+ar[4]); return e.ceLast}; e.ca=(a0,c,h)=>{
e.ce(a0,c,h);return e}; e.cen=function(a0, n=1, c, f) {
e.cenAr=[];let ar;if(isS(a0))ar=a0.split('\n');else ar=a0; for(let t=0;t<n;t++)for(let tn of ar){
let s=e.ce(tn).cls(c); if(f)f(s,e, e.cenAr); e.cenAr.push(s)};return e;}; e.cbn=function(a0,n0=1,n1=1,c0,c1,f0,f1) {
let ar;if(isS(a0))ar=a0.split('\n');else ar=a0; let pt=ar.shift(); e.cen(pt,n0,c0,f0); for(let b of e.cenAr){
b.cen(ar,n1,c1,f1);} return e;}; e.rdmBgc=function(){
e.style.backgroundColor=rdmRgb();return e;}; dgebi(p,e);return e;}; window.dceptq=function(p,t,q=1){
let ear=Array(q); for(let n=0;n<q;q++){
ear.push(dcept(p,t));} return ear;}; dceptc=(p,t,c)=>dcept(p,t).cls(c); dcDiv=(p,c)=>dceptc(p,"div",c); dcArticle=(p,c)=>dceptc(p,"article",c); dcSection=(p,c)=>dceptc(p,"section",c); dcFL=(p,lh,c)=>{
let f=dcept(p,"fieldset").cls(c); f.l=dcept(f,"legend").htm(lh); return f;}; evalab=(p,code)=>dcept(p,"label").cls("evalab").cen("span=->"+code+"=->=->evalabL , span=->的结果是=->=->evalabC , span=->"+eval(code)+"=->=->evalabR"); 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.simpleTableByA2=(p,a2)=>{
let tb=dcept(p,"table").cen(['thead','tbody','tfoot']);tb.h=tb.tHead;let tbd=tb.b=tb.tBody=tb.tBodies[0]; tb.f=tb.tFoot; tb.Ntr=dcept(tb.h,"tr","Ntr"); let ar=a2.shift(); ar.forEach((v)=>dce(tb.Ntr,"th").htm(v)); a2.forEach((row,r)=>{
let tr=dcept(tbd,"tr");row.forEach((v,c)=>{
let td=dce(tr,"td").htm(v).cls("R"+r+"C"+c);});});return tb;}; </script>
</head><body><header id="BodyH">
<label></label><script>{
let s=document.currentScript; let l=s.previousElementSibling; if(!l.innerHTML.length)l.textContent=document.title}</script>
</header><div id="BodyB">
</div><script>const BodyH=dgebi("BodyH") , BodyB=dgebi("BodyB") ; dce(document.body).idefine("BodyF"); dce(BodyB).idefine("BBB");</script>
<script>{
}</script><style> *{
box-sizing:border-box;} table{
border-collapse:collapse;} thead {
color:white; background:#331100; } tbody{
background:#eeeef9; } tbody>:nth-child(2n){
background:#ffeedd; } th,td {
border:1px solid black; } </style><script>{
const SrcArray = [1,2,3,'4','5','6','七','八','九',[1,2,3],{
a:"a",b:"b"},window,document,parseInt,Number,String,Array,Object,Function,document.html,document.body]; const ExeCountAr = [1000, 10000, 100000, 1000000, 3000000]; let tbA2=[['方法','执行次数','用时毫秒']]; function f1(methodStr , MaxCount, fun){
let beginning = Date.now(); for(let c=0;c<MaxCount;c++){
fun(); } let t1=Date.now(); let cost = t1-beginning; let temp=[ methodStr.replaceAll("<","<") , MaxCount , cost ]; tbA2.push(temp); } function f2(){
for(let count of ExeCountAr){
f1(` SrcArray.concat(); ` , count , function(){
SrcArray.concat(); }); f1(` let newArray=SrcArray.concat(); ` , count , function(){
let newArray=SrcArray.concat(); }); f1(` SrcArray.slice(); ` , count , function(){
SrcArray.slice(); }); f1(` let newArray=SrcArray.slice(); ` , count , function(){
let newArray=SrcArray.slice(); }); f1(` [...SrcArray]; ` , count , function(){
[...SrcArray]; }); f1(` let newArray=[...SrcArray]; ` , count , function(){
let newArray=[...SrcArray]; }); f1(` Array.from(SrcArray); ` , count , function(){
Array.from(SrcArray); }); f1(` let newArray=Array.from(SrcArray); ` , count , function(){
let newArray=Array.from(SrcArray); }); f1( ` let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } ` , count , function() {
let newArray=[]; for(let i=0; i<SrcArray.length; i++){
newArray.push(SrcArray[i]); } } ); f1( ` let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } ` , count , function() {
let newArray=[]; for(let a of SrcArray){
newArray.push(a); } } ); f1( ` let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } ` , count , function() {
let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){
newArray[i]=SrcArray[i]; } } ); } } f2(); simpleTableByA2(BBB,tbA2); }</script><script>{
}</script></body></html>
chrome下的结果

| 方法 | 执行次数 | 用时毫秒 |
|---|---|---|
| SrcArray.concat(); | 1000 | 0 |
| let newArray=SrcArray.concat(); | 1000 | 0 |
| SrcArray.slice(); | 1000 | 0 |
| let newArray=SrcArray.slice(); | 1000 | 0 |
| [...SrcArray]; | 1000 | 0 |
| let newArray=[...SrcArray]; | 1000 | 0 |
| Array.from(SrcArray); | 1000 | 0 |
| let newArray=Array.from(SrcArray); | 1000 | 0 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000 | 2 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000 | 2 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 1000 | 1 |
| SrcArray.concat(); | 10000 | 1 |
| let newArray=SrcArray.concat(); | 10000 | 1 |
| SrcArray.slice(); | 10000 | 1 |
| let newArray=SrcArray.slice(); | 10000 | 1 |
| [...SrcArray]; | 10000 | 1 |
| let newArray=[...SrcArray]; | 10000 | 1 |
| Array.from(SrcArray); | 10000 | 0 |
| let newArray=Array.from(SrcArray); | 10000 | 1 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 10000 | 3 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 10000 | 2 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 10000 | 2 |
| SrcArray.concat(); | 100000 | 2 |
| let newArray=SrcArray.concat(); | 100000 | 2 |
| SrcArray.slice(); | 100000 | 2 |
| let newArray=SrcArray.slice(); | 100000 | 1 |
| [...SrcArray]; | 100000 | 3 |
| let newArray=[...SrcArray]; | 100000 | 3 |
| Array.from(SrcArray); | 100000 | 3 |
| let newArray=Array.from(SrcArray); | 100000 | 3 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 100000 | 8 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 100000 | 9 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 100000 | 3 |
| SrcArray.concat(); | 1000000 | 22 |
| let newArray=SrcArray.concat(); | 1000000 | 23 |
| SrcArray.slice(); | 1000000 | 17 |
| let newArray=SrcArray.slice(); | 1000000 | 18 |
| [...SrcArray]; | 1000000 | 25 |
| let newArray=[...SrcArray]; | 1000000 | 26 |
| Array.from(SrcArray); | 1000000 | 30 |
| let newArray=Array.from(SrcArray); | 1000000 | 30 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000000 | 86 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000000 | 91 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 1000000 | 32 |
| SrcArray.concat(); | 3000000 | 65 |
| let newArray=SrcArray.concat(); | 3000000 | 63 |
| SrcArray.slice(); | 3000000 | 53 |
| let newArray=SrcArray.slice(); | 3000000 | 50 |
| [...SrcArray]; | 3000000 | 76 |
| let newArray=[...SrcArray]; | 3000000 | 76 |
| Array.from(SrcArray); | 3000000 | 89 |
| let newArray=Array.from(SrcArray); | 3000000 | 88 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 3000000 | 256 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 3000000 | 263 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 3000000 | 97 |
FireFox下的结果

| 方法 | 执行次数 | 用时毫秒 |
|---|---|---|
| SrcArray.concat(); | 1000 | 2 |
| let newArray=SrcArray.concat(); | 1000 | 0 |
| SrcArray.slice(); | 1000 | 0 |
| let newArray=SrcArray.slice(); | 1000 | 0 |
| [...SrcArray]; | 1000 | 1 |
| let newArray=[...SrcArray]; | 1000 | 1 |
| Array.from(SrcArray); | 1000 | 2 |
| let newArray=Array.from(SrcArray); | 1000 | 1 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000 | 0 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000 | 1 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 1000 | 0 |
| SrcArray.concat(); | 10000 | 3 |
| let newArray=SrcArray.concat(); | 10000 | 1 |
| SrcArray.slice(); | 10000 | 2 |
| let newArray=SrcArray.slice(); | 10000 | 0 |
| [...SrcArray]; | 10000 | 2 |
| let newArray=[...SrcArray]; | 10000 | 3 |
| Array.from(SrcArray); | 10000 | 3 |
| let newArray=Array.from(SrcArray); | 10000 | 3 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 10000 | 2 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 10000 | 1 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 10000 | 2 |
| SrcArray.concat(); | 100000 | 20 |
| let newArray=SrcArray.concat(); | 100000 | 19 |
| SrcArray.slice(); | 100000 | 6 |
| let newArray=SrcArray.slice(); | 100000 | 6 |
| [...SrcArray]; | 100000 | 20 |
| let newArray=[...SrcArray]; | 100000 | 21 |
| Array.from(SrcArray); | 100000 | 27 |
| let newArray=Array.from(SrcArray); | 100000 | 26 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 100000 | 19 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 100000 | 25 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 100000 | 17 |
| SrcArray.concat(); | 1000000 | 194 |
| let newArray=SrcArray.concat(); | 1000000 | 194 |
| SrcArray.slice(); | 1000000 | 51 |
| let newArray=SrcArray.slice(); | 1000000 | 49 |
| [...SrcArray]; | 1000000 | 203 |
| let newArray=[...SrcArray]; | 1000000 | 198 |
| Array.from(SrcArray); | 1000000 | 274 |
| let newArray=Array.from(SrcArray); | 1000000 | 271 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000000 | 188 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 1000000 | 249 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 1000000 | 166 |
| SrcArray.concat(); | 3000000 | 582 |
| let newArray=SrcArray.concat(); | 3000000 | 581 |
| SrcArray.slice(); | 3000000 | 151 |
| let newArray=SrcArray.slice(); | 3000000 | 148 |
| [...SrcArray]; | 3000000 | 612 |
| let newArray=[...SrcArray]; | 3000000 | 587 |
| Array.from(SrcArray); | 3000000 | 826 |
| let newArray=Array.from(SrcArray); | 3000000 | 819 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 3000000 | 563 |
| let newArray=[]; for(let i=0; i<SrcArray.length; i++){ newArray.push(SrcArray[i]); } | 3000000 | 747 |
| let newArray=Array(SrcArray.length); for(let i=0; i<SrcArray.length; i++){ newArray[i]=SrcArray[i]; } | 3000000 | 509 |
边栏推荐
- 每天学一点Scala之 伴生类和伴生对象
- 【23考研】408代码题参考模板——链表
- Composer安装方式
- How to migrate the device data connected by RTSP of EasyCVR platform to EasyNVR?
- Anaconda\Scripts\pip-script.py is not present ? 解决方案
- 群晖系统安装相关文件分享
- 浅析TSINGSEE智能视频分析网关的AI识别技术及应用场景
- CMake库搜索函数居然不搜索LD_LIBRARY_PATH
- EasyNVR更新版本至(V5.3.0)后页面不显示通道配置该如何解决?
- dolphinscheduler添加hana支持
猜你喜欢
随机推荐
腰部外骨骼机器人线性自抗扰控制器参数优化
R语言ggstatsplot包grouped_ggwithinstats函数可视化分组小提琴图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)
jsArray数组复制方法性能测试2207300823
学习笔记——七周成为数据分析师《第一周:数据分析思维》
大手笔!两所“双一流”大学,获75亿元重点支持!
无人艇轨迹跟踪的预设性能抗扰控制研究
C语言学习练习题:汉诺塔(函数与递归)
Apache Log4j2漏洞
R语言筛选时间序列数据的子集(subset time series data)、使用window函数筛选连续日期时间范围内的数据(start参数和end参数分别指定起始和结束时间)
【微信小程序】一文带你搞懂小程序的页面配置和网络数据请求
shell 编程规范与变量
双击Idea图标打不开——解决办法
自从外包干了四年,基本废了...
Lake storehouse which electricity (2) of the project: project using technology and version and the environment
【23考研】408代码题参考模板——顺序表
leetcode207.课程表(判断有向图是否有环)
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
Eleven BUUCTF questions (06)
shell script flow control statement
How to solve the problem that the page does not display the channel configuration after the EasyNVR is updated to (V5.3.0)?









