aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/crypto-hasher.mjs
blob: 73835bc0c953bc7ed92ceff9f326070bf3902403 (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
24
25
26
27
28
29
30
// so it can run in environments without node module resolution
import { bench, run } from "mitata";

import crypto from "node:crypto";

var foo = Buffer.allocUnsafe(16384);
foo.fill(123);

// if ("Bun" in globalThis) {
//   const { CryptoHasher } = Bun;
//   bench("CryptoHasher Blake2b256", () => {
//     var hasher = new CryptoHasher("blake2b256");
//     hasher.update(foo);
//     hasher.digest();
//   });
// }

bench('crypto.createHash("sha512")', () => {
  var hasher = crypto.createHash("sha512");
  hasher.update(foo);
  hasher.digest();
});

bench('crypto.createHash("sha512")', () => {
  var hasher = crypto.createHash("sha512");
  hasher.update(foo);
  hasher.digest();
});

await run();