Re:Faster TypedArrays: Vector Addition in WebAssembly
by brrrrrm on Monday January 03, 2022 @11:52AM
(#29782804)
I fixed your fiddle to get the normal unrolled version 4x faster. Please see: https://jsfiddle.net/Lmzqpr03/
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)
Re:Faster TypedArrays: Vector Addition in WebAssembly
by IvanK_net on Monday January 03, 2022 @02:04PM
(#29784829)
BTW. I replaced every "let" and "contst" with "var" in your code, and it seems to run about 15% faster: https://jsfiddle.net/05xd1oft/
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/
Even with a warmup, the unwrapped version is more than 3x faster.