Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koffi

Package Overview
Dependencies
Maintainers
1
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koffi - npm Package Compare versions

Comparing version 0.9.24 to 0.9.25

benchmark/atoi_cc.cc

5

benchmark/raylib_koffi.js

@@ -105,2 +105,4 @@ #!/usr/bin/env node

let start = performance.now();
for (let i = 0; i < iterations; i++) {

@@ -128,2 +130,5 @@ ImageClearBackground(img, { r: 0, g: 0, b: 0, a: 255 });

}
let time = performance.now()- start;
console.log('Time:', (time / 1000.0).toFixed(2) + 's');
}

@@ -19,2 +19,3 @@ #!/usr/bin/env node

const struct = require('ref-struct-di')(ref);
const koffi = require('../build/koffi.node');
const path = require('path');

@@ -123,2 +124,4 @@

let start = performance.now();
for (let i = 0; i < iterations; i++) {

@@ -146,2 +149,5 @@ r.ImageClearBackground(imgp, new Color({ r: 0, g: 0, b: 0, a: 255 }));

}
let time = performance.now()- start;
console.log('Time:', (time / 1000.0).toFixed(2) + 's');
}

2

package.json
{
"name": "koffi",
"version": "0.9.24",
"version": "0.9.25",
"description": "Fast and simple FFI (foreign function interface) for Node.js",

@@ -5,0 +5,0 @@ "keywords": [

@@ -10,2 +10,4 @@ # Table of contents

- [Benchmarks](#benchmarks)
* [atoi results](#atoi-results)
* [Raylib results](#raylib-results)

@@ -257,31 +259,88 @@ # Introduction

A basic benchmark based around Raylib is available, in three implementations: with Koffi, with node-ffi and with C code using Raylib (as a shared library).
At this stage, two benchmarks are implemented:
* The first one is based around repeated calls to atoi, and has four implementations: one in C++, one calling atoi through an NAPI module, one using Koffi, and one with node-ffi-napi. This is a simple function, thus the JS and FFI overhead is clearly visible.
* The second one is based around Raylib, and will execute much more heavier functions repeatdly. Also in three versions: Koffi, node-ffi-napi and C code.
In order to run it, go to `koffi/benchmark` and run `build.sh` before doing anything else.
In order to run it, go to `koffi/benchmark` and run `../../cnoke/cnoke.js` (or `node ..\..\cnoke\cnoke.js` on Windows) before doing anything else.
Once this is done, you can execute each implementation with `time`, e.g. `time ./raylib_c 2000`.
Once this is done, you can execute each implementation, e.g. `build/atoi_cc 20000000` or `./atoi_koffi.js 20000000`.
Here are some results from 2022-04-15 on my machine (AMD Ryzen™ 7 5800H 16G):
## atoi results
Here are some results from 2022-04-24 on my Linux machine (AMD® Ryzen™ 7 5800H 16G):
```sh
$ time ./raylib_c 200
Iterations: 200
$ build/atoi_cc 20000000
Iterations: 20000000
Time: 0.24s
real 0m8,871s
user 0m8,792s
sys 0m0,016s
$ ./atoi_napi.js 20000000
Iterations: 20000000
Time: 1.56s
$ time ./raylib_koffi.js 200
Iterations: 200
$ ./atoi_koffi.js 20000000
Iterations: 20000000
Time: 2.41s
real 0m13,011s
user 0m12,923s
sys 0m0,032s
# Note: the Node-FFI version does a few setTimeout calls to force the GC to run (around 20
# for the example below), without which Node will consume all memory because the GC never appears
# to run, or not enough. It's not ideal but on the other hand it counts as another limitation
# to Node-FFI performance.
$ ./atoi_node_ffi.js 20000000
Iterations: 20000000
Time: 640.49s
```
$ time ./raylib_node_ffi.js 200
Iterations: 200
And on my Windows machine (Intel® Core™ i5-4460 16G):
real 1m41,523s
user 1m56,623s
sys 0m3,731s
```sh
$ build\atoi_cc.exe 20000000
Iterations: 20000000
Time: 0.66s
$ node atoi_napi.js 20000000
Iterations: 20000000
Time: 3.52s
$ node atoi_koffi.js 20000000
Iterations: 20000000
Time: 4.81s
$ node atoi_node_ffi.js 20000000
Iterations: 20000000
Time: 491.99s
```
## Raylib results
Here are some results from 2022-04-24 on my Linux machine (AMD® Ryzen™ 7 5800H 16G):
```sh
$ build/raylib_cc 100
Iterations: 100
Time: 4.14s
$ ./raylib_koffi.js 100
Iterations: 100
Time: 6.25s
$ ./raylib_node_ffi.js 100
Iterations: 100
Time: 27.13s
```
And on my Windows machine (Intel® Core™ i5-4460 16G):
```sh
$ build\raylib_cc.exe 100
Iterations: 100
Time: 10.53s
$ node raylib_koffi.js 100
Iterations: 100
Time: 14.60s
$ node raylib_node_ffi.js 100
Iterations: 100
Time: 44.97s
```

@@ -55,2 +55,3 @@ #!/usr/bin/env node

const FillPack3 = lib.cdecl('FillPack3', 'void', ['int', 'int', 'int', koffi.out(koffi.pointer(Pack3))]);
const RetPack3 = lib.cdecl('RetPack3', Pack3, ['int', 'int', 'int']);
const AddPack3 = lib.fastcall('AddPack3', 'void', ['int', 'int', 'int', koffi.inout(koffi.pointer(Pack3))]);

@@ -70,2 +71,5 @@ const ConcatenateToInt1 = lib.cdecl('ConcatenateToInt1', 'int64_t', Array(12).fill('int8_t'));

let q = RetPack3(6, 9, -12);
assert.deepEqual(q, { a: 6, b: 9, c: -12 });
AddPack3(6, 9, -12, p);

@@ -72,0 +76,0 @@ assert.deepEqual(p, { a: 7, b: 11, c: -9 });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc