aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/crypto-2190.mjs
blob: dab54f1fdfd4aeb3e423289d7d46a8a281a711a4 (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
// https://github.com/oven-sh/bun/issues/2190
import { bench, run } from "mitata";
import { createHash } from "node:crypto";

const data =
  "Delightful remarkably mr on announcing themselves entreaties favourable. About to in so terms voice at. Equal an would is found seems of. The particular friendship one sufficient terminated frequently themselves. It more shed went up is roof if loud case. Delay music in lived noise an. Beyond genius really enough passed is up.";

const scenarios = [
  { alg: "md5", digest: "hex" },
  { alg: "md5", digest: "base64" },
  { alg: "sha1", digest: "hex" },
  { alg: "sha1", digest: "base64" },
  { alg: "sha256", digest: "hex" },
  { alg: "sha256", digest: "base64" },
];

for (const { alg, digest } of scenarios) {
  bench(`${alg}-${digest}`, () => {
    createHash(alg).update(data).digest(digest);
  });

  if ("Bun" in globalThis) {
    bench(`${alg}-${digest} (Bun.CryptoHasher)`, () => {
      new Bun.CryptoHasher(alg).update(data).digest(digest);
    });
  }
}

run();
ption&id=99a78f85407a7b2d22566a453e5c4a5e19c761eb&follow=1'>Update README.md (#6291)Gravatar TPLJ 1-1/+1 2023-10-09docs: fixing a couple typos (#6331)Gravatar Michael Di Prisco 2-2/+2 2023-10-09fix: support uint8 exit code range (#6303)Gravatar Liz 2-2/+11 2023-10-09Fix array variables preview in debugger (#6379)Gravatar 2hu 1-1/+4 2023-10-07feat(KeyObject) (#5940)Gravatar Ciro Spaciari 106-67/+9342 2023-10-07Exclude more filesGravatar Jarred Sumner 1-1/+1 2023-10-07Exclude more filesGravatar Jarred Sumner 1-1/+2 2023-10-07Update settings.jsonGravatar Jarred Sumner 1-1/+2 2023-10-07Update settings.jsonGravatar Jarred Sumner 1-2/+3 2023-10-06fix a couple install testsGravatar Dylan Conway 1-8/+8 2023-10-06formatGravatar Dylan Conway 1-1/+2 2023-10-06Fix memory leak in fetch() (#6350)Gravatar Jarred Sumner 1-2/+0 2023-10-06[types] allow onLoad plugin callbacks to return undefined (#6346)Gravatar Silver 1-1/+1 2023-10-06docs: `file.stream()` is not a promise (#6337)Gravatar Paul Nodet 1-1/+1