Benchmark of fast inverse square root implementations for NodeJS.
node index.js
Single value inputs:
==========
addon/6: 51.186ms
llvm wasm/6: 13.694ms
wat wasm/6: 10.459ms
simple/6: 9.976ms
js/6: 311.792ms
js external/6: 11.276ms
==========
Array inputs:
==========
addon/1000x10: 0.12ms
wat/1000x10: 0.297ms
simple/1000x10: 0.56ms
==========
addon/1000x100: 0.429ms
wat/1000x100: 1.135ms
simple/1000x100: 0.502ms
==========
addon/1000x1000: 5.03ms
wat/1000x1000: 1.222ms
simple/1000x1000: 5.075ms
==========
addon/1000x10000: 42.844ms
wat/1000x10000: 7.926ms
simple/1000x10000: 48.996ms
/6
- means 1e6 iterations = 1 million
addon
- node-gyp compiled C addon that uses N-APInode-gyp build
llvm wasm
- CLang compiled src/rsqrt.c to WASM. Command:clang --target=wasm32 -nostdlib -Wl,--no-entry -Wl,--export-all -o build/Release/rsqrt.wasm src/rsqrt.c
wat wasm
-wat2wasm
compiled WebAssembly Text Format version of this alg. See src/rsqrt.watnpx wat2wasm src/rsqrt.wat
simple
const simple = (x) => 1 / Math.sqrt(x);
js
JS version from this gistjs external
JS version with buffers outside of function scope
- NodeJS optimizing jit-compiler is amazing
- WASM is the best way to perform computationally-hard operations over arrays for JS
- I suck at C