diff options
author | 2022-09-14 18:25:06 -0700 | |
---|---|---|
committer | 2022-09-14 18:25:06 -0700 | |
commit | b0dd7bee5b22e49f2f2b8af92e4e1c7736f5d9a5 (patch) | |
tree | 67e12b18f4120d1d0814cc4046bd2ceb6d1f0de1 /bench/snippets/crypto.mjs | |
parent | a291c1676f9351a03ae1092993d762c3147cff49 (diff) | |
download | bun-b0dd7bee5b22e49f2f2b8af92e4e1c7736f5d9a5.tar.gz bun-b0dd7bee5b22e49f2f2b8af92e4e1c7736f5d9a5.tar.zst bun-b0dd7bee5b22e49f2f2b8af92e4e1c7736f5d9a5.zip |
Update crypto benchmark
Diffstat (limited to 'bench/snippets/crypto.mjs')
-rw-r--r-- | bench/snippets/crypto.mjs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/bench/snippets/crypto.mjs b/bench/snippets/crypto.mjs index 572e127bc..132e6595d 100644 --- a/bench/snippets/crypto.mjs +++ b/bench/snippets/crypto.mjs @@ -1,18 +1,25 @@ // so it can run in environments without node module resolution import { bench, run } from "../node_modules/mitata/src/cli.mjs"; +var crypto = globalThis.crypto; // web crypto is not a global in node -if (!globalThis.crypto) { - globalThis.crypto = await import("crypto"); +if (!crypto) { + crypto = await import("crypto"); } -var foo = new Uint8Array(2); -bench("crypto.getRandomValues()", () => { +var foo = new Uint8Array(65536); +bench("crypto.getRandomValues(65536)", () => { crypto.getRandomValues(foo); }); +var small = new Uint8Array(32); +bench("crypto.getRandomValues(32)", () => { + crypto.getRandomValues(small); +}); + bench("crypto.randomUUID()", () => { - crypto.randomUUID(); + // node uses a rope string for each hex byte so any subsequent operation after creating it is slow + return crypto.randomUUID()[2]; }); await run(); |