You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//example.jsmapTag="Map Spent Time is"eachTag="Each Spend Time is"mapArr=eachArr=[...Array(1000000)]console.time(mapTag)mapArr.map((i,index)=>{returnindex*2})console.timeEnd(mapTag)console.time(eachTag)eachArr.forEach((i,index)=>{returneachArr[index]=index*2})console.timeEnd(eachTag)
今天看到一篇文章,一个大神写的。可以看Speed Considerations这个地方,他说他那里测试是
map
比forEach
快不少。我觉得不太可能,毕竟
map
是返回一个新的数组呀。从上面这个例子可以发现不是这样的。
不对呀,jsperf应该不会出问题的。难道是forEach有提升吗?找了下,没有找到相关的资料,值看到了说17年八月初forEach有提升十倍,那也不对呀,上面的文章提到的是2017年12月份。
jsperf的工作方式。
比较好奇啊,这是为啥呐。
The text was updated successfully, but these errors were encountered: