From 7bfa302b75c2450a872dc6b5de0002a9c7959ea9 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 14 Sep 2022 04:12:32 -0700 Subject: 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 --- bench/snippets/crypto.mjs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 bench/snippets/crypto.mjs (limited to 'bench/snippets') 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(); -- cgit v1.2.3