r/javascript • • May 13 '18

[Performance] Lodash vs ES6 : map()

https://medium.com/@peterchang_82818/es6-lodash-native-javascript-nodejs-example-tutorial-map-function-functional-programming-performance-speed-69645e613049
0 Upvotes

18 comments sorted by

View all comments

3

u/voidvector May 13 '18

If you are going to micro-benchmark, you might as well add for.

for would out-perform both in 90% of the real world scenarios due to all the compiler optimization available (e.g. loop unrolling, loop invariant code motion, memory fragmentation, garbage collection).

Ref: https://en.wikipedia.org/wiki/Loop_optimization

3

u/oculus42 May 13 '18

I added a for loop to my fork's benchmark test:

In Node 10.1.0, map is faster (in this run).

native map x 22,775 ops/sec ±19.38% (85 runs sampled)
lodash x 7,761 ops/sec ±0.86% (88 runs sampled)
lodash/map x 8,874 ops/sec ±1.32% (92 runs sampled)
lodash.map x 9,313 ops/sec ±0.97% (90 runs sampled)
native for x 18,955 ops/sec ±1.23% (94 runs sampled)
Fastest is native map

Note that the margin of error is also higher on the map. Subsequent runs were trading or sharing the "fastest" title between the two native functions.