forked from 25051998/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplus100.bun.js
52 lines (45 loc) · 973 Bytes
/
plus100.bun.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { run, bench, group, baseline } from "mitata";
import { dlopen, suffix } from "bun:ffi";
import { readdirSync } from "fs";
const {
symbols: {
plus100: { native: plus100 },
noop,
},
close,
} = dlopen(`./plus100.dylib`, {
plus100: {
args: ["int32_t"],
returns: "int32_t",
},
noop: {
args: [],
},
});
const {
plus100: plus100napi,
noop: noopNapi,
} = require("./plus100-napi/index.js");
group("plus100", () => {
bench("plus100(1) ffi", () => {
plus100(1);
});
bench("plus100(1) napi", () => {
plus100napi(1);
});
});
group("noop", () => {
bench("noop() ffi", () => {
noop();
});
bench("noop() napi", () => {
noopNapi();
});
});
// collect option collects benchmark returned values into array
// prevents gc and can help with jit optimizing out functions
await run({ collect: false, percentiles: true });
console.log("\n");
if (plus100(1) !== 101) {
throw new Error("plus100(1) !== 101");
}