diff options
Diffstat (limited to 'bench/ffi/bun.js')
-rw-r--r-- | bench/ffi/bun.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/bench/ffi/bun.js b/bench/ffi/bun.js new file mode 100644 index 000000000..ccf81f366 --- /dev/null +++ b/bench/ffi/bun.js @@ -0,0 +1,33 @@ +import { run, bench, group } from "mitata"; +import { ptr, dlopen, CString } from "bun:ffi"; +const { napiNoop, napiHash, napiString } = require("./src/ffi_napi_bench.node"); + +const { + symbols: { + ffi_noop: { native: ffi_noop }, + ffi_hash: { native: ffi_hash }, + ffi_string: { native: ffi_string }, + }, +} = dlopen("./src/ffi_napi_bench.node", { + ffi_noop: { args: [], returns: "void" }, + ffi_string: { args: [], returns: "ptr" }, + ffi_hash: { args: ["ptr", "usize"], returns: "u32" }, +}); + +const bytes = new Uint8Array(64); + +group("bun:ffi", () => { + bench("noop", () => ffi_noop()); + bench("hash", () => ffi_hash(ptr(bytes), bytes.byteLength)); + + bench("c string", () => new CString(ffi_string())); +}); + +group("bun:napi", () => { + bench("noop", () => napiNoop()); + bench("hash", () => napiHash(bytes)); + + bench("string", () => napiString()); +}); + +await run(); |