diff options
author | 2022-09-14 04:12:32 -0700 | |
---|---|---|
committer | 2022-09-14 04:12:32 -0700 | |
commit | 7bfa302b75c2450a872dc6b5de0002a9c7959ea9 (patch) | |
tree | c01a806611a0cbff3c47cfb9bc098d14e7d1667c /bench/snippets | |
parent | 0935ab14d6cad3a3c80bee5b585381cfbbe74699 (diff) | |
download | bun-7bfa302b75c2450a872dc6b5de0002a9c7959ea9.tar.gz bun-7bfa302b75c2450a872dc6b5de0002a9c7959ea9.tar.zst bun-7bfa302b75c2450a872dc6b5de0002a9c7959ea9.zip |
Make `crypto.getRandomValues()` faster + fix > 1 byte/element typed arrays
Fix crypto.getRandomValues() with > 1 byte element typed arrays
Fixes https://github.com/oven-sh/bun/issues/1237
Diffstat (limited to 'bench/snippets')
-rw-r--r-- | bench/snippets/crypto.mjs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bench/snippets/crypto.mjs b/bench/snippets/crypto.mjs new file mode 100644 index 000000000..572e127bc --- /dev/null +++ b/bench/snippets/crypto.mjs @@ -0,0 +1,18 @@ +// so it can run in environments without node module resolution +import { bench, run } from "../node_modules/mitata/src/cli.mjs"; + +// web crypto is not a global in node +if (!globalThis.crypto) { + globalThis.crypto = await import("crypto"); +} + +var foo = new Uint8Array(2); +bench("crypto.getRandomValues()", () => { + crypto.getRandomValues(foo); +}); + +bench("crypto.randomUUID()", () => { + crypto.randomUUID(); +}); + +await run(); |