aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-27 03:44:23 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-04-27 03:44:23 -0700
commit93833337999c66c7c6888f85ab12fe9d27136e99 (patch)
tree376c6a023b0f99cb4c6579f665d31e8328f53bef
parent4558ea712a40c25306868577eea0211c838daf55 (diff)
downloadbun-93833337999c66c7c6888f85ab12fe9d27136e99.tar.gz
bun-93833337999c66c7c6888f85ab12fe9d27136e99.tar.zst
bun-93833337999c66c7c6888f85ab12fe9d27136e99.zip
Add microbenchmark
-rw-r--r--bench/snippets/write-file-huge.mjs42
1 files changed, 42 insertions, 0 deletions
diff --git a/bench/snippets/write-file-huge.mjs b/bench/snippets/write-file-huge.mjs
new file mode 100644
index 000000000..62790c6eb
--- /dev/null
+++ b/bench/snippets/write-file-huge.mjs
@@ -0,0 +1,42 @@
+import { Buffer } from "node:buffer";
+import { writeFile } from "node:fs/promises";
+import { bench, run } from "mitata";
+
+var hugeFile = Buffer.alloc(1024 * 1024 * 64);
+var medFile = Buffer.alloc(1024 * 1024 * 16);
+var humongousFile = Buffer.alloc(1024 * 1024 * 256);
+
+bench(
+ `fs.writeFile ${new Intl.NumberFormat("en-US", {
+ style: "unit",
+ unit: "megabyte",
+ unitDisplay: "narrow",
+ }).format(humongousFile.byteLength / 1024 / 1024)}`,
+ async () => {
+ await writeFile("/tmp/bun.bench-out.humongousFile.txt" + ((Math.random() * 65432) | 0).toString(16), humongousFile);
+ },
+);
+
+bench(
+ `fs.writeFile ${new Intl.NumberFormat("en-US", {
+ style: "unit",
+ unit: "megabyte",
+ unitDisplay: "narrow",
+ }).format(hugeFile.byteLength / 1024 / 1024)}`,
+ async () => {
+ await writeFile("/tmp/bun.bench-out.huge.txt" + ((Math.random() * 65432) | 0).toString(16), hugeFile);
+ },
+);
+
+bench(
+ `fs.writeFile ${new Intl.NumberFormat("en-US", {
+ style: "unit",
+ unit: "megabyte",
+ unitDisplay: "narrow",
+ }).format(medFile.byteLength / 1024 / 1024)}`,
+ async () => {
+ await writeFile("/tmp/bun.bench-out.medium.txt" + ((Math.random() * 65432) | 0).toString(16), medFile);
+ },
+);
+
+await run();