From 93833337999c66c7c6888f85ab12fe9d27136e99 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Thu, 27 Apr 2023 03:44:23 -0700 Subject: Add microbenchmark --- bench/snippets/write-file-huge.mjs | 42 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bench/snippets/write-file-huge.mjs (limited to 'bench/snippets/write-file-huge.mjs') 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(); -- cgit v1.2.3