Here's what the builtin forEach function does: https://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/array.js#1078
Notably, for every index it checks if the array actually contains that index. This check is mandated by the ECMAScript specification, see http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf chapter 15.4.4.18. On Thu, May 23, 2013 at 10:37 AM, 刘玉龙 <[email protected]> wrote: > I found an interesting thing in V8 engine when I was testing underscore.js > library. > > For arrays, the > >> for (var i = 0; i < len; i++) > > implementation can ran 24700 ops(operations per second), while the native > function > >> Array.prototype.forEach > > only got 14200 ops. > > Then I tried IE10, in which the `nativeForEach` can reach a number of > 43500. > > I checked the source code of V8 engine, but could not find out why this > native forEach function is so slow. > Can anybody explain this? Thank you. > > -- > -- > v8-users mailing list > [email protected] > http://groups.google.com/group/v8-users > --- > You received this message because you are subscribed to the Google Groups > "v8-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
