A place to compare JS
vs WASM
vs native
speeds.
The benchmark is calculating PI with a Leibniz formula
The algorithm is implemented in
- Plain JavaScript
- Plain C
- AssemblyScript
You can find the algorithm implementations in the implementations
directory
You can find executing scripts in then runners
directory
Not compiled AOT (obviously)
Executed by node v16.13.2
Loaded by a require
function
Measured with performance.now()
Compiled with the clang (cc) compiler
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
cc implementations/plainC.c -O2 -o build/plainC
Executed natively
./runners/plainC
Measured with clock()
function from time.h
Compiled with asc v0.20.13
node_modules/.bin/asc implementations/assemblyScript.ts --target release
Executed by node v16.13.2
Loaded with WebAssembly.instantiate
Measured with performance.now()
Executed by wasm3 v0.5.0
Loaded with --func
argument
Measured with the time
command
Executed by python 3.10.4
Loaded with pywasm3 v0.5.0
Measured with time.time()
function
assemblyscript
for all AssemblyScript benchmarksnpm install
wasm3
for AssemblyScript -> WASM -> WASM3 CLI benchmark# macOS: brew install wabt
pywasm3
for AssemblyScript -> WASM -> PyWASM3 benchmarkpip3 install pywasm3
npm run build
npm run build:assembly-script
npm run build:c
npm run start
npm run start:js
npm run start:c
npm run start:wasm-node
npm run start:wasm3-cli
npm run start:pywasm3
Measured on a MacBook Air M1 16Gb RAM
Method | Time, ms |
---|---|
Plain JS | 4861 |
Plain C | 4119 |
WASM on node | 4035 |
wasm3 CLI | 39327 |
pywasm3 | 39652 |