bun ffi benchmark (vs c, luajit, node, python)
based on https://bun.sh/blog/compile-and-run-c-in-js
$ bun install
$ bun run bench.js
$ yarn install
$ yarn global add node-gyp
$ node-gyp rebuild
$ node bench_napi.cjs
- note: using google benchmark library. below is example for macos.
$ brew install google-benchmark
$ clang++ ./bench.cpp -L/opt/homebrew/lib -l benchmark -O3 -I/opt/homebrew/include -o bench
$ ./bench
$ clang -shared -fPIC -O3 -o libmyRandom.dylib myRandom.c
# (.dylib should be .so on linux)
$ luajit bench.lua
$ clang -shared -fPIC -O3 -o libmyRandom.dylib myRandom.c
# (.dylib should be .so on linux)
$ python bench.py
Tested on M1 Macbook Air.
- C: 7.05 ns /iter
- bun: 12.54 ns /iter
- node: 11.47 ns /iter
- luajit: 16.84 ns /iter
- python: 135.26 ns /iter
(Used environment)
- clang: 19.1.2
- bun: 1.1.34
- node: v22.9.0
- node-gyp: v10.2.0
- LuaJIT: 2.1.1710088188
- Python: 3.11.5