https://github.com/usagi/neon-vs-node-ffi-napi
Benchmark: NEON vs. node-ffi-napi vs. pure Node.js
https://github.com/usagi/neon-vs-node-ffi-napi
Last synced: 11 months ago
JSON representation
Benchmark: NEON vs. node-ffi-napi vs. pure Node.js
- Host: GitHub
- URL: https://github.com/usagi/neon-vs-node-ffi-napi
- Owner: usagi
- Created: 2020-03-30T19:19:10.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-30T20:57:23.000Z (about 6 years ago)
- Last Synced: 2025-03-03T00:14:26.646Z (over 1 year ago)
- Language: JavaScript
- Size: 23.4 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# neon-vs-node-ffi-napi
This is a benchmark project of `NEON` vs. `node-ffi-napi` vs. pure-`Node.js`. It's focused to a marshalling cost.
1. The "pure" is: `Node.js` ↺ `Node.js`
2. The "NEON" is: `Node.js` ⇄ `NEON` ⇄ `native code`
3. The "node-ffi-napi" is: `Node.js` ⇄ `node-ffi-napi` ⇄ `native code`
## Usage
```sh
git clone git@github.com:usagi/neon-vs-node-ffi-napi.git
cd neon-vs-node-ffi-napi
yarn start
```
## A result
| | pure | NEON | node-ffi-napi |
| ------ | ----------- | ----------- | ------------- |
| empty | 47.92550206 | 128.3124983 | 5800.287876 |
| rng | 35.47475487 | 175.1873791 | 5176.462751 |
| buffer | 175394.375 | 534.950003 | 59332.4 |
Unit: `[ns/function-call]`; See also "Main codes" section.
There are two important points these are the marshalling cost comparison and the useful usage. These individual values are not important.
1. You may not need a native codes and a marshallings if you want to use only lightweight implements. Maybe, a marshalling cost be over than native code advantage.
2. You should use `NEON` if you want speedup mainly with a native code. Unfortunately, `node-ffi-napi` is so slow.
3. You may need a native code and a marshallings if you need to operate buffers such as `ArrayBuffer`.
Note: This result scored in 2020-03-31. Using Threadripper 2990WX machine.
## Main codes
- [index.js](index.js) ... Benchmarking code, pure `Node.js` implements, `node-ffi-napi` marshalling part.
- [native/src/lib.rs](native/src/lib.rs) ... `NEON` marshalling part.
- [workspace.rs/backend/src/lib.rs](workspace.rs/backend/src/lib.rs) ... backend pure `Rust` implements.
## License
MIT
## Author
USAGI.NETWORK / Usagi Ito