diff options
author | 2023-04-14 00:55:01 -0400 | |
---|---|---|
committer | 2023-04-13 21:55:01 -0700 | |
commit | 3a2fd65f20d3b4e99c89f789acec5e5e40615008 (patch) | |
tree | d0491f57d2f612aaec638f52bdb36155e5b3bdde /bench/snippets/crypto-2190.mjs | |
parent | 267a38f6fc226156a50292945a697308e7201e69 (diff) | |
download | bun-3a2fd65f20d3b4e99c89f789acec5e5e40615008.tar.gz bun-3a2fd65f20d3b4e99c89f789acec5e5e40615008.tar.zst bun-3a2fd65f20d3b4e99c89f789acec5e5e40615008.zip |
use a lazyily initialized stream for `node:crypto` `createHash` (#2652)
* lazy hash
* finish up crypto stuff
* remove lockfiles
* ok
* add pipe test
* update this lockfile
* remove unrelated crypto benchmark from this file
Diffstat (limited to 'bench/snippets/crypto-2190.mjs')
-rw-r--r-- | bench/snippets/crypto-2190.mjs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bench/snippets/crypto-2190.mjs b/bench/snippets/crypto-2190.mjs new file mode 100644 index 000000000..dab54f1fd --- /dev/null +++ b/bench/snippets/crypto-2190.mjs @@ -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(); |