4 ms·
There's no description of what's actually being tested but you can find it in the formulas.js file: https://github.com/dg92/Performance-analysis-es6/blob/master
by zawerf 8y ago
There's no description of what's actually being tested but you can find it in the formulas.js file: https://github.com/dg92/Performance-analysis-es6/blob/master/formulas.js https://github.com/dg92/Performance-analysis-es6/blob/master...
Even on one of the first lines, there was already a mistake with how reduce is called:
let avg = 0;
console.time('js reduce');
avg = posts.reduce(p => avg+= (+p.downvotes+ +p.upvotes+ +p.commentCount)/3,0);
avg = avg/posts.length;
console.timeEnd('js reduce')
The way he's using it makes it no different from a forEach. It should be
`posts.reduce((p, accumulation) => accumulation + blah, 0)` instead.
Also the timing isn't very sophisticated. Doing microbenchmarking right is basically black magic but the mistakes he's making are really basic (only running each version of the code once, not preventing dead code elimination, etc). Someone mentioned elsewhere that the timing for the large case is faster than the small and my guess is that the entire calculation got JIT'd out since it's unused.
- pier25 8y agoMaybe, but OTOH if you need to know about the micro benchmarking intricacies to use some native methods maybe there is something wrong with the native methods. The difference with a simple for() are quite significant.
- denomer 8y agoThanks for pointing out a mistake on reduce, I missed that. The data collected is not on running it once, the results are avg. of running same code at least 15 times.