diff options
Diffstat (limited to 'bench/snippets/buffer-to-string.mjs')
-rw-r--r-- | bench/snippets/buffer-to-string.mjs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bench/snippets/buffer-to-string.mjs b/bench/snippets/buffer-to-string.mjs new file mode 100644 index 000000000..f4a169572 --- /dev/null +++ b/bench/snippets/buffer-to-string.mjs @@ -0,0 +1,29 @@ +import { bench, run } from "./runner.mjs"; +import { Buffer } from "node:buffer"; +import crypto from "node:crypto"; + +const bigBuffer = Buffer.from("hello world".repeat(10000)); +const converted = bigBuffer.toString("base64"); +const uuid = crypto.randomBytes(16); + +bench(`Buffer(${bigBuffer.byteLength}).toString('base64')`, () => { + return bigBuffer.toString("base64"); +}); + +bench(`Buffer(${uuid.byteLength}).toString('base64')`, () => { + return uuid.toString("base64"); +}); + +bench(`Buffer(${bigBuffer.byteLength}).toString('hex')`, () => { + return bigBuffer.toString("hex"); +}); + +bench(`Buffer(${uuid.byteLength}).toString('hex')`, () => { + return uuid.toString("hex"); +}); + +bench(`Buffer(${bigBuffer.byteLength}).toString('ascii')`, () => { + return bigBuffer.toString("ascii"); +}); + +await run(); |