diff options
author | 2022-09-07 21:20:41 -0700 | |
---|---|---|
committer | 2022-09-07 21:20:41 -0700 | |
commit | 8af05c28a3dea66df24a7e818a7d5c9ecd4ddc5a (patch) | |
tree | 9c84aa9e2eaf08ac6071c447496f57aa3b2df154 /bench/snippets/write.bun.js | |
parent | 970600724da7e7f48341c3951181a0797abba431 (diff) | |
download | bun-8af05c28a3dea66df24a7e818a7d5c9ecd4ddc5a.tar.gz bun-8af05c28a3dea66df24a7e818a7d5c9ecd4ddc5a.tar.zst bun-8af05c28a3dea66df24a7e818a7d5c9ecd4ddc5a.zip |
Add benchmark for small write() performance
Diffstat (limited to 'bench/snippets/write.bun.js')
-rw-r--r-- | bench/snippets/write.bun.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bench/snippets/write.bun.js b/bench/snippets/write.bun.js new file mode 100644 index 000000000..190604a44 --- /dev/null +++ b/bench/snippets/write.bun.js @@ -0,0 +1,24 @@ +import { bench, run } from "mitata"; +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(); |