aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/write.bun.js
blob: 67fbbe3b250bdc3897a32a49432ac2691f85e702 (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
import { bench, run } from "./runner.mjs";
import { write } from "bun";
import { openSync } from "fs";

bench('write(/tmp/foo.txt, "short string")', async () => {
  await write("/tmp/foo.txt", "short string");
});

const buffer = Buffer.from("short string");
bench('write(/tmp/foo.txt, Buffer.from("short string"))', async () => {
  await write("/tmp/foo.txt", buffer);
});

const fd = openSync("/tmp/foo.txt", "w");

bench('write(fd, "short string")', async () => {
  await write(fd, "short string");
});

bench('write(fd, Buffer.from("short string"))', async () => {
  await write(fd, buffer);
});

await run();