aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/crypto.mjs
blob: 484a4295dd611ef0aba32df452e346442de923e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// so it can run in environments without node module resolution
import { bench, run } from "../node_modules/mitata/src/cli.mjs";
import crypto from "node:crypto";
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()", () => {
  // node uses a rope string for each hex byte so any subsequent operation after creating it is slow
  return crypto.randomUUID()[2];
});

bench("crypto.randomInt()", () => {
  return crypto.randomInt(0, 100);
});

await run();