The results are practically invalid since the tests don't actually care about the results. This means that javascript engines can and will optimise away critical code.
*************** Map performance check ***************
js map: 15.636ms
for loop: 8.461ms
for each: 17.376ms
lodash map: 18.545ms
*************** Map performance check with result check ***************
js map: 6.106ms
sum: 49886314
for loop: 22.985ms
sum: 49886314
for each: 7.250ms
sum: 49886314
lodash map: 27.305ms
sum: 49886314
The latter case is where I just console.log the sum of commentCounts after each run and outside the timing blocks. This completely turns the results around.
The results are practically invalid since the tests don't actually care about the results. This means that javascript engines can and will optimise away critical code.
*************** Map performance check ***************
js map: 15.636ms
for loop: 8.461ms
for each: 17.376ms
lodash map: 18.545ms
*************** Map performance check with result check ***************
js map: 6.106ms
sum: 49886314
for loop: 22.985ms
sum: 49886314
for each: 7.250ms
sum: 49886314
lodash map: 27.305ms
sum: 49886314
The latter case is where I just console.log the sum of commentCounts after each run and outside the timing blocks. This completely turns the results around.