Files
bun.sh/bench/ffi/plus100/add3.deno.js
2022-07-05 00:54:42 -07:00

31 lines
633 B
JavaScript

import { run, bench, group, baseline } from "https://esm.sh/mitata";
const {
symbols: { add3: add3, noop },
close,
} = Deno.dlopen("./plus100.dylib", {
add3: {
parameters: ["i32", "i32", "i32"],
result: "i32",
},
noop: {
parameters: [],
result: "void",
},
});
bench("add3(1,2,3) ", () => {
add3(1, 2, 3);
});
bench("noop() ", () => {
noop();
});
// collect option collects benchmark returned values into array
// prevents gc and can help with jit optimizing out functions
await run({ collect: false, percentiles: true });
if (add3(1, 2, 3) !== 1 + 2 + 3) {
throw new Error("add3(1) !== 101");
}