标签:filter 其他 根据 png span ndt font bsp 重要
一、创建一个1000万、甚至1亿。
二、分别写9个方法 getForRunTime()、getForOfRunTime()、getForInRunTime()、getForeachRunTime()、getMapRunTime()、getFilterRunTime()、getEveryRunTime()、getSomeRunTime()、getreduceRunTIme()、
1、getForRunTime()
2、getForRunTime()
3、getForInRunTime()
4、getForeachRunTime()
5、getMapRunTime()
6、getFilterRunTime()
7、getEveryRunTime()
8、getSomeRunTime()
9、getreduceRunTIme()
三、同时执行所有方法
四、游览器F12打开 开发者工具点击Console 查看执行时间
五、我们来看下各种方法的执行时间,其中有一个every循环运行时间为0毫秒 原因是执行时间太短,Date.now()获取当前时间已经不能满足,来写一个更加精准的算法 console.time与console.timeEnd
把原来的startTime变量与endTime变量整行删除 换成Console.time("1")与Console.endTime("1");用every例子:
console.time与console.timeEnd(包含的字符串内容必须相等 不然打印不出来)
其他方法也如此 再来看看打印时间
本次测试并不是为了检验哪个方法快,最重要根据需求,选择适合的方法。
标签:filter 其他 根据 png span ndt font bsp 重要
原文地址:https://www.cnblogs.com/Duck-King/p/12127984.html