4x unwrap: https://jsfiddle.net/49j7htdz/1/
8x unwrap: https://jsfiddle.net/49j7htdz/2/
4x unwrap: https://jsfiddle.net/49j7htdz/1/
8x unwrap: https://jsfiddle.net/49j7htdz/2/
That being said, I’m seeing a very similar relative difference in your fiddle to what I see in the benchmark I posted.
No kidding, this can be seriously misleading.
IMO JS (and likely many other JIT VM) benchmarks should run:
- multiple cold starts
- multiple pre-warmed starts (essentially run your bench twice, discard the results, run it again)
- isolated cases
- shared runtime cases with evenly distributed ordering
All of those will reveal different performance characteristics you may want to know about, and people evaluating your results should be able to know about. Cold starts are a worst case scenario of each implementation, warmed should show a more ideal outcome. Isolated will again highlight the perf of each implementation on its own merits, whereas shared runtime should help highlight how interacting with other real-world code affects VM optimization of that implementation.
There are a few clickable benchmark examples in the readme: https://github.com/xpl/what-code-is-faster#what-code-is-fast...
Reminds me of prof. Emery Berger's talk, Performance Matters: https://www.youtube-nocookie.com/embed/r-TLSBdHe1A
Even with a warmup, the unwrapped version is more than 3x faster.
Largely, the use modern javascript and proper benchmarking made the results more consistent with the benchmark posted.
This included
1) avoiding the use of "var" (using let for scoped iterator variables and const for unchanging references)
2) using proper warmup (10% of runs)
3) isolating the benchmarked code into a function that can be invoked within a loop
4) reseting the values of the arrays being added between benchmarks (to prevent any NaNs/infinities from cropping up)
Inserting the loop into a function really speeds it up in Chrome. Also, I have noticed, that for Float32Array, the rolled / unrolled performance is almost identical, but for Uint32Array, unrolled is about 30% faster: https://jsfiddle.net/aq06p94f/
That's pretty opaquely rude, just FYI.