Skip to content

funatsufumiya/bun-c-luajit-bench

Repository files navigation

bun-c-luajit-bench

bun ffi benchmark (vs c, luajit, node, python)

based on https://bun.sh/blog/compile-and-run-c-in-js

Usage

Bun

$ bun install
$ bun run bench.js

Node.js

$ yarn install
$ yarn global add node-gyp
$ node-gyp rebuild
$ node bench_napi.cjs

C

  • 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

Luajit

$ clang -shared -fPIC -O3 -o libmyRandom.dylib myRandom.c
# (.dylib should be .so on linux)
$ luajit bench.lua

Python

$ clang -shared -fPIC -O3 -o libmyRandom.dylib myRandom.c
# (.dylib should be .so on linux)
$ python bench.py

Result

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

About

bun ffi benchmark (vs c, luajit, node, python)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published