Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.

AlexXanderGrib/qrsqrt-node-benchmark

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Q_rsqrt NodeJS benchmark

Benchmark of fast inverse square root implementations for NodeJS.

Run

node index.js

Output

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

Variants

  • addon - node-gyp compiled C addon that uses N-API
    node-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.wat
    npx wat2wasm src/rsqrt.wat
  • simple
    const simple = (x) => 1 / Math.sqrt(x);
  • js JS version from this gist
  • js external JS version with buffers outside of function scope

Conclusion

  • NodeJS optimizing jit-compiler is amazing
  • WASM is the best way to perform computationally-hard operations over arrays for JS
  • I suck at C

About

Q_rsqrt NodeJS benchmark

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published