TypeScript:各种遍历数组的⽅法与执⾏时间
⼀、创建⼀个1000万、甚⾄1亿。
⼆、分别写9个⽅法 getForRunTime()、getForOfRunTime()、getForInRunTime()、getForeachRunTime()、getMapRunTime()、getFilterRunTime()、getEveryRunTime()、getSomeRunTime()、getreduceRunTIme()、
1、getForRunTime()
2、getForRunTime()
3、getForInRunTime()
typescript 字符串转数组
4、getForeachRunTime()
5、getMapRunTime()
6、getFilterRunTime()
7、getEveryRunTime()
8、getSomeRunTime()
9、getreduceRunTIme()
三、同时执⾏所有⽅法
四、游览器F12打开开发者⼯具点击Console 查看执⾏时间
五、我们来看下各种⽅法的执⾏时间,其中有⼀个every循环运⾏时间为0毫秒原因是执⾏时间太短,w()获取当前时间已经不能满⾜,来写⼀个更加精准的算法 console.time与console.timeEnd
把原来的startTime变量与endTime变量整⾏删除换成Console.time("1")与dTime("1");⽤every例⼦:
console.time与console.timeEnd(包含的字符串内容必须相等不然打印不出来)
其他⽅法也如此再来看看打印时间
本次测试并不是为了检验哪个⽅法快,最重要根据需求,选择适合的⽅法。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。