aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/crypto-stream.mjs
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-06-01 17:31:36 -0400
committerGravatar GitHub <noreply@github.com> 2023-06-01 14:31:36 -0700
commit2c1694f63bc4eb279aa708f216037d2e6204eaf1 (patch)
tree6784f39bc74a9d7b2d46e62e27ccec8ec1855d5d /bench/snippets/crypto-stream.mjs
parentae277a0dec2acddb2bebc2e46b26bc1543a55914 (diff)
downloadbun-2c1694f63bc4eb279aa708f216037d2e6204eaf1.tar.gz
bun-2c1694f63bc4eb279aa708f216037d2e6204eaf1.tar.zst
bun-2c1694f63bc4eb279aa708f216037d2e6204eaf1.zip
Fix streams breaking on reverted EventEmitter / Make Discord.js work (#2913)
* Revert "Revert "use a lazyily initialized stream for `node:crypto` `createHash` (#2652)"" This reverts commit 613bb4822ee8f4fbfd78aef391e2db8f07659a6f. * Revert "Revert "implement `node:events` in javascript (#2604)"" This reverts commit a4d0a1961abe0c6073e15cc6f7c0601b74f2e3f7. * oops * fix entrypoints stuff * fix hash copy * use native events for node streams and crypto * requested changes * oops * make discord.js work * fix webkit hash * headers tojson
Diffstat (limited to 'bench/snippets/crypto-stream.mjs')
-rw-r--r--bench/snippets/crypto-stream.mjs26
1 files changed, 26 insertions, 0 deletions
diff --git a/bench/snippets/crypto-stream.mjs b/bench/snippets/crypto-stream.mjs
new file mode 100644
index 000000000..3560563d9
--- /dev/null
+++ b/bench/snippets/crypto-stream.mjs
@@ -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();