Skip to content

Commit

Permalink
use a lazyily initialized stream for node:crypto createHash (oven…
Browse files Browse the repository at this point in the history
…-sh#2652)

* lazy hash

* finish up crypto stuff

* remove lockfiles

* ok

* add pipe test

* update this lockfile

* remove unrelated crypto benchmark from this file
  • Loading branch information
paperclover authored Apr 14, 2023
1 parent 267a38f commit 3a2fd65
Show file tree
Hide file tree
Showing 13 changed files with 265 additions and 14,032 deletions.
1,986 changes: 0 additions & 1,986 deletions bench/package-lock.json

This file was deleted.

29 changes: 29 additions & 0 deletions bench/snippets/crypto-2190.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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();
26 changes: 26 additions & 0 deletions bench/snippets/crypto-stream.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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}`, () => {
const hasher = createHash(alg);
hasher.write(data);
hasher.end();
hasher.read();
});
}

run();
Binary file added bench/sqlite/bun.lockb
Binary file not shown.
Loading

0 comments on commit 3a2fd65

Please sign in to comment.