Performance-Analysis-JS
Performance-Analysis-JS copied to clipboard
This tests are not valid.
You are not taking in consideration time needed to work with memory, but you have to in such tests, where main work depends exactly on construction of big arrays and freeing them before next test.
Simple example. In mapPerformance(posts) execution time of "forEach" depends on running order, just move "forEach" block before "for loop", and you will see it starts to run "faster" than "for loop".
I have changed order and added 2 copies of tests, several runs: posts.length: 100000
*************** Map performance check ***************
js map: 76.214ms
forEach1: 18.749ms
for loop1: 41.964ms
for loop2: 25.268ms
forEach2: 44.676ms
lodash map: 39.380ms
*************** Map performance check ***************
js map: 54.923ms
forEach1: 22.339ms
for loop1: 40.497ms
for loop2: 25.301ms
forEach2: 36.331ms
lodash map: 46.882ms
*************** Map performance check ***************
js map: 52.755ms
forEach1: 13.488ms
for loop1: 36.412ms
for loop2: 18.201ms
forEach2: 32.484ms
lodash map: 29.668ms
*************** Map performance check ***************
js map: 58.978ms
forEach1: 18.157ms
for loop1: 42.817ms
for loop2: 25.558ms
forEach2: 40.048ms
lodash map: 37.493ms
What we see? What conclusion? What can we say with confidence? Just that forEach and for loop have no difference and you can choose what you want.
PS: node v10.16.1