Performance - Array.forEach vs implemented version

后端 未结 2 1035
温柔的废话
温柔的废话 2021-01-02 02:15

I would have expected a native version to be faster.

What gives?

http://jsperf.com/native-vs-implmented-0

Implementation

<         


        
2条回答
  •  感动是毒
    2021-01-02 02:36

    forEach() does more than your implementation. If you don't need the extra effort that the official algorithm performs, a simple implementation like yours is indeed preferable when raw speed is required.

    The 'official' algorithm is described in the MDN reference for Array.forEach.

提交回复
热议问题