Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/funatsufumiya/bun-c-luajit-bench

bun ffi benchmark (vs c, luajit, node, python)
https://github.com/funatsufumiya/bun-c-luajit-bench

bun luajit nodejs

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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

```bash
$ bun install
$ bun run bench.js
```

### Node.js

```bash
$ 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.

```bash
$ brew install google-benchmark
$ clang++ ./bench.cpp -L/opt/homebrew/lib -l benchmark -O3 -I/opt/homebrew/include -o bench
$ ./bench
```

### Luajit

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

### Python

```bash
$ 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