aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/write-file-huge.mjs
blob: 62790c6eb269e22e17808470ac2a9f7db99c5cd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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();