aboutsummaryrefslogtreecommitdiff
path: root/bench/copyfile/node.mitata.mjs
blob: 93833cfcfa154c80082e926d4062a08a96295454 (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
import { copyFileSync, writeFileSync } from "node:fs";
import { bench, run } from "mitata";

const size = parseInt(process.env.FILE_SIZE, 10) || 1024 * 16;
const rand = new Float64Array(size);
for (let i = 0; i < size; i++) {
  rand[i] = Math.random();
}
const dest = `/tmp/fs-test-copy-file-${(Math.random() * 100000 + 100).toString(
  32
)}`;
const src = `/tmp/fs-test-copy-file-${(Math.random() * 100000 + 100).toString(
  32
)}`;
writeFileSync(src, new Buffer(rand.buffer));

const srcBuf = new TextEncoder().encode(src);
const destBuf = new TextEncoder().encode(dest);
bench(`copyFileSync(${rand.buffer.byteLength} bytes)`, () =>
  copyFileSync(srcBuf, destBuf)
);

await run();