aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench/ffi/plus100/add3.bun.js49
-rw-r--r--bench/ffi/plus100/add3.deno.js30
-rw-r--r--bench/ffi/plus100/add3.napi.mjs19
-rw-r--r--bench/ffi/plus100/plus100.c1
-rw-r--r--bench/sqlite/download-northwind.sh6
5 files changed, 102 insertions, 3 deletions
diff --git a/bench/ffi/plus100/add3.bun.js b/bench/ffi/plus100/add3.bun.js
new file mode 100644
index 000000000..4e79d4cea
--- /dev/null
+++ b/bench/ffi/plus100/add3.bun.js
@@ -0,0 +1,49 @@
+import { run, bench, group, baseline } from "mitata";
+import { dlopen, suffix } from "bun:ffi";
+import { readdirSync } from "fs";
+
+const {
+ symbols: {
+ add3: { native: add3 },
+ noop,
+ },
+ close,
+} = dlopen(`./plus100.dylib`, {
+ add3: {
+ args: ["int32_t", "int32_t", "int32_t"],
+ returns: "int32_t",
+ },
+ noop: {
+ args: [],
+ },
+});
+const { add3: add3napi, noop: noopNapi } = require("./plus100-napi/index.js");
+
+group("add3", () => {
+ bench("add3(1,2,3) ffi", () => {
+ add3(1, 2, 3);
+ });
+
+ bench("add3(1,2,3) napi", () => {
+ add3napi(1, 2, 3);
+ });
+});
+
+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 (add3(1, 2, 3) !== 1 + 2 + 3) {
+ throw new Error("add3(1) !== 101");
+}
diff --git a/bench/ffi/plus100/add3.deno.js b/bench/ffi/plus100/add3.deno.js
new file mode 100644
index 000000000..75508d39a
--- /dev/null
+++ b/bench/ffi/plus100/add3.deno.js
@@ -0,0 +1,30 @@
+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");
+}
diff --git a/bench/ffi/plus100/add3.napi.mjs b/bench/ffi/plus100/add3.napi.mjs
new file mode 100644
index 000000000..fd96d8eb5
--- /dev/null
+++ b/bench/ffi/plus100/add3.napi.mjs
@@ -0,0 +1,19 @@
+import { bench, run } from "mitata";
+
+const { add3, noop } =
+ "Bun" in globalThis
+ ? require("./plus100-napi")
+ : (await import("module")).createRequire(import.meta.url)("./plus100-napi");
+
+bench("add3(1,2,3) napi", () => {
+ add3(1, 2, 3);
+});
+bench("noop() napi", () => {
+ noop();
+});
+await run({ collect: false, percentiles: true });
+console.log("\n");
+
+if (add3(1, 2, 3) !== 1 + 2 + 3) {
+ throw new Error("plus100(1) !== 101");
+}
diff --git a/bench/ffi/plus100/plus100.c b/bench/ffi/plus100/plus100.c
index bdecda7e0..17ceb67a0 100644
--- a/bench/ffi/plus100/plus100.c
+++ b/bench/ffi/plus100/plus100.c
@@ -3,6 +3,7 @@
int32_t plus100(int32_t a);
int32_t plus100(int32_t a) { return a + 100; }
+int32_t add3(int32_t a, int32_t b, int32_t c) { return a + b + c; }
void noop(void);
void noop(void) {} \ No newline at end of file
diff --git a/bench/sqlite/download-northwind.sh b/bench/sqlite/download-northwind.sh
index 7502e8314..5fc523a14 100644
--- a/bench/sqlite/download-northwind.sh
+++ b/bench/sqlite/download-northwind.sh
@@ -2,9 +2,9 @@
set -euo pipefail
rm -rf Northwind_large.sqlite.zip
-wget https://github.com/jpwhite3/northwind-SQLite3/blob/master/Northwind_large.sqlite.zip?raw=true
-unzip Northwind_large.sqlite.zip
-rm Northwind_large.sqlite.zip
+curl -LJO https://github.com/jpwhite3/northwind-SQLite3/blob/master/Northwind_large.sqlite.zip?raw=true
+unzip Northwind_large.sqlite.zip?raw=true
+rm Northwind_large.sqlite.zip?raw=true
mv Northwind_large.sqlite /tmp/northwind.sqlite
rm -rf Northwind* || echo ""
rm -rf __MACOSX