array.forEach running faster than native iteration? How?

前端 未结 5 862
隐瞒了意图╮
隐瞒了意图╮ 2021-02-08 19:38

http://jsperf.com/testing-foreach-vs-for-loop

It was my understanding that Test Case 2 should run more slowly than Test Case 1 -- I wanted to see how much more slowly. I

5条回答
  •  旧巷少年郎
    2021-02-08 20:09

    Reading length from array at each iteration may be slow, but forEach is comomonly slower, cause function call isn't cheap operation in js.

    PS: forEach is 14% slower on FF10.

提交回复
热议问题