From 0e3273e3cfc8206b4078e32e49048ee6e82ab3f3 Mon Sep 17 00:00:00 2001 From: Parsa Ghadimi Date: Fri, 15 Sep 2023 17:24:47 -0400 Subject: [PATCH] publish blake3js benchmark --- lib/blake3-js/README.md | 178 ++++- lib/blake3-js/bench.json | 1128 +++++++++++++++++++++++++++ lib/blake3-js/deno.lock | 38 +- lib/blake3-js/src/blake3_benches.ts | 51 ++ 4 files changed, 1360 insertions(+), 35 deletions(-) create mode 100644 lib/blake3-js/bench.json create mode 100644 lib/blake3-js/src/blake3_benches.ts diff --git a/lib/blake3-js/README.md b/lib/blake3-js/README.md index 1a81551a1..ee29635da 100644 --- a/lib/blake3-js/README.md +++ b/lib/blake3-js/README.md @@ -1,3 +1,177 @@ -# (WIP) Pure JavaScript Blake3 +# Pure JavaScript Blake3 -And it's blazingly fast. +*And it's blazingly fast.* + +This is the source code of a pure JavaScript implementation of the [Blake3](https://github.com/BLAKE3-team/BLAKE3) +algorithm, the implementations aims to be as efficient as possible. This includes both: + +1. The size of the dependency. +2. The performance. + +## Benchmarks + +The following benchmarks compare the performance of this implementation vs web assembly compilation of the +original implementation. + +```txt +cpu: Apple M1 Max +runtime: deno 1.36.4 (aarch64-apple-darwin) + +file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts +benchmark time (avg) iter/s (min … max) p75 p99 p995 +---------------------------------------------------------------------- ----------------------------- + + +Sha256 0B 2.13 µs/iter 469,357.1 (2.11 µs … 2.27 µs) 2.13 µs 2.27 µs 2.27 µs +Optimized 0B 337.63 ns/iter 2,961,804.2 (320.22 ns … 1.59 µs) 330.91 ns 374.4 ns 1.59 µs +WASM 0B 505.2 ns/iter 1,979,426.5 (497.21 ns … 530.78 ns) 507.89 ns 528.54 ns 530.78 ns + +summary + Optimized 0B + 1.5x faster than WASM 0B + 6.31x faster than Sha256 0B + +Sha256 32B 2.14 µs/iter 468,242.9 (2.1 µs … 2.2 µs) 2.16 µs 2.2 µs 2.2 µs +Optimized 32B 366.45 ns/iter 2,728,899.1 (349.22 ns … 1.36 µs) 361.2 ns 380.66 ns 1.36 µs +WASM 32B 523.19 ns/iter 1,911,362.4 (517.56 ns … 539.71 ns) 527.6 ns 534.4 ns 539.71 ns + +summary + Optimized 32B + 1.43x faster than WASM 32B + 5.83x faster than Sha256 32B + +Sha256 48B 2.19 µs/iter 456,054.1 (2.18 µs … 2.26 µs) 2.19 µs 2.26 µs 2.26 µs +Optimized 48B 368.49 ns/iter 2,713,751.5 (358.75 ns … 420.24 ns) 369.72 ns 392.18 ns 420.24 ns +WASM 48B 527.24 ns/iter 1,896,667.2 (519.55 ns … 567.62 ns) 531.56 ns 556.82 ns 567.62 ns + +summary + Optimized 48B + 1.43x faster than WASM 48B + 5.95x faster than Sha256 48B + +Sha256 96B 3.18 µs/iter 314,309.8 (3.16 µs … 3.26 µs) 3.18 µs 3.26 µs 3.26 µs +Optimized 96B 442.74 ns/iter 2,258,652.9 (433.54 ns … 453.92 ns) 444.21 ns 453.71 ns 453.92 ns +WASM 96B 648.19 ns/iter 1,542,748.4 (628.38 ns … 700.15 ns) 653.95 ns 700.15 ns 700.15 ns + +summary + Optimized 96B + 1.46x faster than WASM 96B + 7.19x faster than Sha256 96B + +Sha256 128B 4.11 µs/iter 243,058.6 (4.08 µs … 4.15 µs) 4.13 µs 4.15 µs 4.15 µs +Optimized 128B 455.5 ns/iter 2,195,410.3 (445.61 ns … 462.29 ns) 457.32 ns 461.67 ns 462.29 ns +WASM 128B 661 ns/iter 1,512,864.7 (631.73 ns … 706.71 ns) 664.86 ns 706.71 ns 706.71 ns + +summary + Optimized 128B + 1.45x faster than WASM 128B + 9.03x faster than Sha256 128B + +Sha256 256B 6.13 µs/iter 163,137.9 (6.09 µs … 6.2 µs) 6.16 µs 6.2 µs 6.2 µs +Optimized 256B 629.88 ns/iter 1,587,600.7 (617.97 ns … 664.11 ns) 630.91 ns 664.11 ns 664.11 ns +WASM 256B 936.24 ns/iter 1,068,103.9 (923.91 ns … 968.28 ns) 939.22 ns 968.28 ns 968.28 ns + +summary + Optimized 256B + 1.49x faster than WASM 256B + 9.73x faster than Sha256 256B + +Sha256 512B 10.23 µs/iter 97,713.5 (9.5 µs … 158.21 µs) 10.21 µs 13.21 µs 14.46 µs +Optimized 512B 976.67 ns/iter 1,023,882.5 (964.6 ns … 1.01 µs) 978.26 ns 1.01 µs 1.01 µs +WASM 512B 1.49 µs/iter 670,194.0 (1.48 µs … 1.58 µs) 1.49 µs 1.58 µs 1.58 µs + +summary + Optimized 512B + 1.53x faster than WASM 512B + 10.48x faster than Sha256 512B + +Sha256 1Kib 18.33 µs/iter 54,555.4 (17.21 µs … 168.33 µs) 18.5 µs 22.54 µs 24.33 µs +Optimized 1Kib 1.66 µs/iter 603,355.2 (1.61 µs … 1.68 µs) 1.67 µs 1.68 µs 1.68 µs +WASM 1Kib 2.55 µs/iter 392,488.6 (2.53 µs … 2.57 µs) 2.55 µs 2.57 µs 2.57 µs + +summary + Optimized 1Kib + 1.54x faster than WASM 1Kib + 11.06x faster than Sha256 1Kib + +Sha256 8Kib 131.62 µs/iter 7,597.8 (128.79 µs … 243.42 µs) 130.96 µs 144.58 µs 205.5 µs +Optimized 8Kib 12.07 µs/iter 82,863.8 (11.58 µs … 151.17 µs) 12.08 µs 12.71 µs 12.96 µs +WASM 8Kib 19.38 µs/iter 51,607.6 (18.58 µs … 876.04 µs) 19.33 µs 21 µs 23.08 µs + +summary + Optimized 8Kib + 1.61x faster than WASM 8Kib + 10.91x faster than Sha256 8Kib + +Sha256 16Kib 264.66 µs/iter 3,778.4 (249.08 µs … 3.12 ms) 263.08 µs 299.12 µs 392.54 µs +Optimized 16Kib 23.92 µs/iter 41,800.8 (23.58 µs … 51.25 µs) 23.92 µs 26.58 µs 27.75 µs +WASM 16Kib 38.67 µs/iter 25,857.2 (38 µs … 198.12 µs) 38.58 µs 41.62 µs 43.71 µs + +summary + Optimized 16Kib + 1.62x faster than WASM 16Kib + 11.06x faster than Sha256 16Kib + +Sha256 32Kib 524.95 µs/iter 1,904.9 (499.75 µs … 820.04 µs) 523.5 µs 663.21 µs 680.92 µs +Optimized 32Kib 47.72 µs/iter 20,953.8 (45.75 µs … 93.54 µs) 47.5 µs 52.58 µs 56.12 µs +WASM 32Kib 76.99 µs/iter 12,988.0 (74.12 µs … 319.17 µs) 76.75 µs 81.67 µs 84.92 µs + +summary + Optimized 32Kib + 1.61x faster than WASM 32Kib + 11x faster than Sha256 32Kib + +Sha256 64Kib 1.04 ms/iter 960.7 (1.02 ms … 1.26 ms) 1.04 ms 1.19 ms 1.21 ms +Optimized 64Kib 93.18 µs/iter 10,731.5 (91.33 µs … 190.92 µs) 94.38 µs 102.83 µs 107.42 µs +WASM 64Kib 150.83 µs/iter 6,630.2 (149.25 µs … 189.46 µs) 150.29 µs 161.12 µs 168.71 µs + +summary + Optimized 64Kib + 1.62x faster than WASM 64Kib + 11.17x faster than Sha256 64Kib + +Sha256 128Kib 2.03 ms/iter 493.0 (1.98 ms … 2.53 ms) 2.04 ms 2.24 ms 2.26 ms +Optimized 128Kib 190.29 µs/iter 5,255.1 (188.79 µs … 220.04 µs) 190.62 µs 198.96 µs 205.33 µs +WASM 128Kib 311.99 µs/iter 3,205.2 (299.83 µs … 394 µs) 312.5 µs 329.42 µs 338.29 µs + +summary + Optimized 128Kib + 1.64x faster than WASM 128Kib + 10.66x faster than Sha256 128Kib + +Sha256 256Kib 4.15 ms/iter 240.8 (4 ms … 4.73 ms) 4.16 ms 4.46 ms 4.73 ms +Optimized 256Kib 380.61 µs/iter 2,627.3 (377.54 µs … 429.96 µs) 381.54 µs 401.21 µs 405.88 µs +WASM 256Kib 622.52 µs/iter 1,606.4 (617 µs … 669.25 µs) 623.58 µs 647.17 µs 656.79 µs + +summary + Optimized 256Kib + 1.64x faster than WASM 256Kib + 10.91x faster than Sha256 256Kib + +Sha256 512Kib 8.25 ms/iter 121.3 (8.14 ms … 8.57 ms) 8.25 ms 8.57 ms 8.57 ms +Optimized 512Kib 764.08 µs/iter 1,308.8 (755.71 µs … 816.54 µs) 765.79 µs 797.17 µs 802.5 µs +WASM 512Kib 1.24 ms/iter 804.0 (1.23 ms … 1.33 ms) 1.25 ms 1.28 ms 1.29 ms + +summary + Optimized 512Kib + 1.63x faster than WASM 512Kib + 10.79x faster than Sha256 512Kib + +Sha256 1MB 16.52 ms/iter 60.5 (16.31 ms … 16.87 ms) 16.67 ms 16.87 ms 16.87 ms +Optimized 1MB 1.53 ms/iter 655.7 (1.51 ms … 1.62 ms) 1.53 ms 1.57 ms 1.6 ms +WASM 1MB 2.48 ms/iter 402.9 (2.47 ms … 2.54 ms) 2.48 ms 2.54 ms 2.54 ms + +summary + Optimized 1MB + 1.63x faster than WASM 1MB + 10.83x faster than Sha256 1MB + +Sha256 100MB 1.65 s/iter 0.6 (1.63 s … 1.67 s) 1.66 s 1.67 s 1.67 s +Optimized 100MB 151.68 ms/iter 6.6 (148.33 ms … 153.89 ms) 152.3 ms 153.89 ms 153.89 ms +WASM 100MB 247.05 ms/iter 4.0 (244.95 ms … 248.78 ms) 248.49 ms 248.78 ms 248.78 ms + +summary + Optimized 100MB + 1.63x faster than WASM 100MB + 10.87x faster than Sha256 100MB +``` diff --git a/lib/blake3-js/bench.json b/lib/blake3-js/bench.json new file mode 100644 index 000000000..b081f83c3 --- /dev/null +++ b/lib/blake3-js/bench.json @@ -0,0 +1,1128 @@ +{ + "runtime": "Deno/1.36.4 aarch64-apple-darwin", + "cpu": "Apple M1 Max", + "benches": [ + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "0B", + "name": "Sha256 0B", + "baseline": false, + "results": [ + { + "ok": { + "n": 33, + "min": 2046.7292, + "max": 2371.1334, + "avg": 2185.072354545455, + "p75": 2235.5458, + "p99": 2371.1334, + "p995": 2371.1334, + "p999": 2371.1334, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "0B", + "name": "Optimized 0B", + "baseline": false, + "results": [ + { + "ok": { + "n": 164, + "min": 308.6292, + "max": 1545.2125, + "avg": 326.4876298780489, + "p75": 321.15, + "p99": 338.8417, + "p995": 1545.2125, + "p999": 1545.2125, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "0B", + "name": "WASM 0B", + "baseline": false, + "results": [ + { + "ok": { + "n": 109, + "min": 484.5666, + "max": 571.5375, + "avg": 508.2859733944954, + "p75": 514.35, + "p99": 553.6542, + "p995": 571.5375, + "p999": 571.5375, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "32B", + "name": "Sha256 32B", + "baseline": false, + "results": [ + { + "ok": { + "n": 34, + "min": 2092.65, + "max": 2577.7041, + "avg": 2185.2957088235294, + "p75": 2245.375, + "p99": 2577.7041, + "p995": 2577.7041, + "p999": 2577.7041, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "32B", + "name": "Optimized 32B", + "baseline": false, + "results": [ + { + "ok": { + "n": 151, + "min": 336.7625, + "max": 1310.9333, + "avg": 360.92497284768206, + "p75": 355.9167, + "p99": 477.0875, + "p995": 1310.9333, + "p999": 1310.9333, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "32B", + "name": "WASM 32B", + "baseline": false, + "results": [ + { + "ok": { + "n": 105, + "min": 496.95, + "max": 587.8667, + "avg": 527.1214247619047, + "p75": 533.9083, + "p99": 581.0959, + "p995": 587.8667, + "p999": 587.8667, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "48B", + "name": "Sha256 48B", + "baseline": false, + "results": [ + { + "ok": { + "n": 33, + "min": 2152.5666, + "max": 2389.6834, + "avg": 2219.374866666667, + "p75": 2225.2375, + "p99": 2389.6834, + "p995": 2389.6834, + "p999": 2389.6834, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "48B", + "name": "Optimized 48B", + "baseline": false, + "results": [ + { + "ok": { + "n": 147, + "min": 346.0083, + "max": 428.4167, + "avg": 364.57196258503404, + "p75": 367.725, + "p99": 414.2292, + "p995": 428.4167, + "p999": 428.4167, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "48B", + "name": "WASM 48B", + "baseline": false, + "results": [ + { + "ok": { + "n": 107, + "min": 508.05, + "max": 538.85, + "avg": 516.1685738317757, + "p75": 519.1875, + "p99": 528.7125, + "p995": 538.85, + "p999": 538.85, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "96B", + "name": "Sha256 96B", + "baseline": false, + "results": [ + { + "ok": { + "n": 26, + "min": 3071.3917, + "max": 3414.7625, + "avg": 3183.588946153847, + "p75": 3262.4875, + "p99": 3414.7625, + "p995": 3414.7625, + "p999": 3414.7625, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "96B", + "name": "Optimized 96B", + "baseline": false, + "results": [ + { + "ok": { + "n": 125, + "min": 420.5542, + "max": 487.5167, + "avg": 437.01193040000004, + "p75": 441.0583, + "p99": 479.2375, + "p995": 487.5167, + "p999": 487.5167, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "96B", + "name": "WASM 96B", + "baseline": false, + "results": [ + { + "ok": { + "n": 88, + "min": 620.8667, + "max": 685.5084, + "avg": 641.5994375, + "p75": 649.1875, + "p99": 685.5084, + "p995": 685.5084, + "p999": 685.5084, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "128B", + "name": "Sha256 128B", + "baseline": false, + "results": [ + { + "ok": { + "n": 23, + "min": 3964.8916, + "max": 4215.5, + "avg": 4040.43567826087, + "p75": 4096.6083, + "p99": 4215.5, + "p995": 4215.5, + "p999": 4215.5, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "128B", + "name": "Optimized 128B", + "baseline": false, + "results": [ + { + "ok": { + "n": 123, + "min": 430.3958, + "max": 464.325, + "avg": 444.7048463414632, + "p75": 450.95, + "p99": 462.35, + "p995": 464.325, + "p999": 464.325, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "128B", + "name": "WASM 128B", + "baseline": false, + "results": [ + { + "ok": { + "n": 85, + "min": 629.7334, + "max": 970.1625, + "avg": 669.9167141176468, + "p75": 668.8167, + "p99": 970.1625, + "p995": 970.1625, + "p999": 970.1625, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "256B", + "name": "Sha256 256B", + "baseline": false, + "results": [ + { + "ok": { + "n": 19, + "min": 5913.3375, + "max": 6563.1792, + "avg": 6044.620626315789, + "p75": 6073.85, + "p99": 6563.1792, + "p995": 6563.1792, + "p999": 6563.1792, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "256B", + "name": "Optimized 256B", + "baseline": false, + "results": [ + { + "ok": { + "n": 93, + "min": 597.2459, + "max": 655.1291, + "avg": 608.5614301075269, + "p75": 608.6417, + "p99": 655.1291, + "p995": 655.1291, + "p999": 655.1291, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "256B", + "name": "WASM 256B", + "baseline": false, + "results": [ + { + "ok": { + "n": 63, + "min": 902.1958, + "max": 1119.6166, + "avg": 946.270173015873, + "p75": 947.7208, + "p99": 1119.6166, + "p995": 1119.6166, + "p999": 1119.6166, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "512B", + "name": "Sha256 512B", + "baseline": false, + "results": [ + { + "ok": { + "n": 49696, + "min": 9416.0, + "max": 2033167.0, + "avg": 10064.0, + "p75": 10000.0, + "p99": 12625.0, + "p995": 13666.0, + "p999": 72417.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "512B", + "name": "Optimized 512B", + "baseline": false, + "results": [ + { + "ok": { + "n": 61, + "min": 934.625, + "max": 1423.9083, + "avg": 985.8872950819672, + "p75": 988.2792, + "p99": 1423.9083, + "p995": 1423.9083, + "p999": 1423.9083, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "512B", + "name": "WASM 512B", + "baseline": false, + "results": [ + { + "ok": { + "n": 42, + "min": 1442.2416, + "max": 2528.5292, + "avg": 1605.300395238095, + "p75": 1585.8667, + "p99": 2528.5292, + "p995": 2528.5292, + "p999": 2528.5292, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "1Kib", + "name": "Sha256 1Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 26544, + "min": 17125.0, + "max": 490917.0, + "avg": 18844.0, + "p75": 18666.0, + "p99": 31875.0, + "p995": 41875.0, + "p999": 138042.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "1Kib", + "name": "Optimized 1Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 41, + "min": 1611.3, + "max": 1765.025, + "avg": 1664.0934926829266, + "p75": 1687.025, + "p99": 1765.025, + "p995": 1765.025, + "p999": 1765.025, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "1Kib", + "name": "WASM 1Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 30, + "min": 2464.45, + "max": 2614.025, + "avg": 2521.5429233333334, + "p75": 2547.8459, + "p99": 2614.025, + "p995": 2614.025, + "p999": 2614.025, + "highPrecision": false, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "8Kib", + "name": "Sha256 8Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 3868, + "min": 125083.0, + "max": 266791.0, + "avg": 129625.0, + "p75": 129875.0, + "p99": 168458.0, + "p995": 215792.0, + "p999": 258541.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "8Kib", + "name": "Optimized 8Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 41626, + "min": 11541.0, + "max": 179958.0, + "avg": 12015.0, + "p75": 12083.0, + "p99": 12750.0, + "p995": 13625.0, + "p999": 20125.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "8Kib", + "name": "WASM 8Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 25829, + "min": 18583.0, + "max": 340833.0, + "avg": 19366.0, + "p75": 19334.0, + "p99": 23291.0, + "p995": 26042.0, + "p999": 36375.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "16Kib", + "name": "Sha256 16Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 1945, + "min": 247541.0, + "max": 3264166.0, + "avg": 258451.0, + "p75": 257750.0, + "p99": 310417.0, + "p995": 405708.0, + "p999": 721667.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "16Kib", + "name": "Optimized 16Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 21451, + "min": 22875.0, + "max": 147334.0, + "avg": 23321.0, + "p75": 23167.0, + "p99": 26833.0, + "p995": 31125.0, + "p999": 38292.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "16Kib", + "name": "WASM 16Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 13207, + "min": 37084.0, + "max": 144500.0, + "avg": 37888.0, + "p75": 38167.0, + "p99": 41875.0, + "p995": 44709.0, + "p999": 54583.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "32Kib", + "name": "Sha256 32Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 995, + "min": 494375.0, + "max": 716292.0, + "avg": 508023.0, + "p75": 507500.0, + "p99": 635250.0, + "p995": 664458.0, + "p999": 716292.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "32Kib", + "name": "Optimized 32Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 10705, + "min": 45666.0, + "max": 119792.0, + "avg": 46751.0, + "p75": 47291.0, + "p99": 54875.0, + "p995": 58250.0, + "p999": 68500.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "32Kib", + "name": "WASM 32Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 6656, + "min": 74208.0, + "max": 241125.0, + "avg": 75240.0, + "p75": 74667.0, + "p99": 84542.0, + "p995": 89625.0, + "p999": 103167.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "64Kib", + "name": "Sha256 64Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 501, + "min": 987958.0, + "max": 1310333.0, + "avg": 1018746.0, + "p75": 1026458.0, + "p99": 1213584.0, + "p995": 1268875.0, + "p999": 1310333.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "64Kib", + "name": "Optimized 64Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 5388, + "min": 91292.0, + "max": 205459.0, + "avg": 92988.0, + "p75": 94084.0, + "p99": 110958.0, + "p995": 117166.0, + "p999": 140875.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "64Kib", + "name": "WASM 64Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 3299, + "min": 149500.0, + "max": 248792.0, + "avg": 152044.0, + "p75": 152583.0, + "p99": 175958.0, + "p995": 188333.0, + "p999": 225625.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "128Kib", + "name": "Sha256 128Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 254, + "min": 1974667.0, + "max": 2674708.0, + "avg": 2057999.0, + "p75": 2089750.0, + "p99": 2278458.0, + "p995": 2291083.0, + "p999": 2674708.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "128Kib", + "name": "Optimized 128Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 2624, + "min": 183291.0, + "max": 247833.0, + "avg": 191304.0, + "p75": 194459.0, + "p99": 226708.0, + "p995": 230917.0, + "p999": 246083.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "128Kib", + "name": "WASM 128Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 1626, + "min": 300000.0, + "max": 523666.0, + "avg": 309416.0, + "p75": 312708.0, + "p99": 344708.0, + "p995": 348250.0, + "p999": 414417.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "256Kib", + "name": "Sha256 256Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 131, + "min": 3957500.0, + "max": 5385375.0, + "avg": 4131529.0, + "p75": 4198166.0, + "p99": 5215167.0, + "p995": 5385375.0, + "p999": 5385375.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "256Kib", + "name": "Optimized 256Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 1332, + "min": 367292.0, + "max": 420333.0, + "avg": 378378.0, + "p75": 382041.0, + "p99": 394000.0, + "p995": 399292.0, + "p999": 406333.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "256Kib", + "name": "WASM 256Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 815, + "min": 615000.0, + "max": 670500.0, + "avg": 621144.0, + "p75": 621750.0, + "p99": 644417.0, + "p995": 649083.0, + "p999": 670500.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "512Kib", + "name": "Sha256 512Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 71, + "min": 8154208.0, + "max": 8552083.0, + "avg": 8279071.0, + "p75": 8308959.0, + "p99": 8552083.0, + "p995": 8552083.0, + "p999": 8552083.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "512Kib", + "name": "Optimized 512Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 667, + "min": 755042.0, + "max": 841333.0, + "avg": 761956.0, + "p75": 762833.0, + "p99": 790958.0, + "p995": 809625.0, + "p999": 841333.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "512Kib", + "name": "WASM 512Kib", + "baseline": false, + "results": [ + { + "ok": { + "n": 413, + "min": 1234375.0, + "max": 1286583.0, + "avg": 1240845.0, + "p75": 1241333.0, + "p99": 1271417.0, + "p995": 1274750.0, + "p999": 1286583.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "1MB", + "name": "Sha256 1MB", + "baseline": false, + "results": [ + { + "ok": { + "n": 41, + "min": 16308500.0, + "max": 16835750.0, + "avg": 16509257.0, + "p75": 16653959.0, + "p99": 16835750.0, + "p995": 16835750.0, + "p999": 16835750.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "1MB", + "name": "Optimized 1MB", + "baseline": false, + "results": [ + { + "ok": { + "n": 339, + "min": 1468750.0, + "max": 1601083.0, + "avg": 1523666.0, + "p75": 1529333.0, + "p99": 1581125.0, + "p995": 1584541.0, + "p999": 1601083.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "1MB", + "name": "WASM 1MB", + "baseline": false, + "results": [ + { + "ok": { + "n": 211, + "min": 2471542.0, + "max": 2586875.0, + "avg": 2488967.0, + "p75": 2488333.0, + "p99": 2556334.0, + "p995": 2576959.0, + "p999": 2586875.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "100MB", + "name": "Sha256 100MB", + "baseline": false, + "results": [ + { + "ok": { + "n": 11, + "min": 1633126917.0, + "max": 1712754542.0, + "avg": 1663524429.0, + "p75": 1677320333.0, + "p99": 1712754542.0, + "p995": 1712754542.0, + "p999": 1712754542.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "100MB", + "name": "Optimized 100MB", + "baseline": false, + "results": [ + { + "ok": { + "n": 14, + "min": 147587625.0, + "max": 152643083.0, + "avg": 149785980.0, + "p75": 150436667.0, + "p99": 152643083.0, + "p995": 152643083.0, + "p999": 152643083.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + }, + { + "origin": "file:///Users/parsa/Code/Fleek/lightning/lib/blake3-js/src/blake3_benches.ts", + "group": "100MB", + "name": "WASM 100MB", + "baseline": false, + "results": [ + { + "ok": { + "n": 12, + "min": 244759167.0, + "max": 282193875.0, + "avg": 250242410.0, + "p75": 247888291.0, + "p99": 282193875.0, + "p995": 282193875.0, + "p999": 282193875.0, + "highPrecision": true, + "usedExplicitTimers": false + } + } + ] + } + ] +} diff --git a/lib/blake3-js/deno.lock b/lib/blake3-js/deno.lock index 6c5b247e0..b3c2b2ca5 100644 --- a/lib/blake3-js/deno.lock +++ b/lib/blake3-js/deno.lock @@ -1,38 +1,10 @@ { "version": "2", "remote": { - "https://deno.land/std@0.201.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", - "https://deno.land/std@0.201.0/assert/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.201.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.201.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", - "https://deno.land/std@0.201.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", - "https://deno.land/std@0.201.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", - "https://deno.land/std@0.201.0/assert/assert_equals.ts": "d8ec8a22447fbaf2fc9d7c3ed2e66790fdb74beae3e482855d75782218d68227", - "https://deno.land/std@0.201.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", - "https://deno.land/std@0.201.0/assert/assert_false.ts": "a9962749f4bf5844e3fa494257f1de73d69e4fe0e82c34d0099287552163a2dc", - "https://deno.land/std@0.201.0/assert/assert_greater.ts": "ae2158a2d19313bf675bf7251d31c6dc52973edb12ac64ac8fc7064152af3e63", - "https://deno.land/std@0.201.0/assert/assert_greater_or_equal.ts": "1439da5ebbe20855446cac50097ac78b9742abe8e9a43e7de1ce1426d556e89c", - "https://deno.land/std@0.201.0/assert/assert_instance_of.ts": "3aedb3d8186e120812d2b3a5dea66a6e42bf8c57a8bd927645770bd21eea554c", - "https://deno.land/std@0.201.0/assert/assert_is_error.ts": "c21113094a51a296ffaf036767d616a78a2ae5f9f7bbd464cd0197476498b94b", - "https://deno.land/std@0.201.0/assert/assert_less.ts": "aec695db57db42ec3e2b62e97e1e93db0063f5a6ec133326cc290ff4b71b47e4", - "https://deno.land/std@0.201.0/assert/assert_less_or_equal.ts": "5fa8b6a3ffa20fd0a05032fe7257bf985d207b85685fdbcd23651b70f928c848", - "https://deno.land/std@0.201.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", - "https://deno.land/std@0.201.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", - "https://deno.land/std@0.201.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", - "https://deno.land/std@0.201.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", - "https://deno.land/std@0.201.0/assert/assert_not_strict_equals.ts": "ca6c6d645e95fbc873d25320efeb8c4c6089a9a5e09f92d7c1c4b6e935c2a6ad", - "https://deno.land/std@0.201.0/assert/assert_object_match.ts": "d8fc2867cfd92eeacf9cea621e10336b666de1874a6767b5ec48988838370b54", - "https://deno.land/std@0.201.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", - "https://deno.land/std@0.201.0/assert/assert_strict_equals.ts": "b1f538a7ea5f8348aeca261d4f9ca603127c665e0f2bbfeb91fa272787c87265", - "https://deno.land/std@0.201.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", - "https://deno.land/std@0.201.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", - "https://deno.land/std@0.201.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", - "https://deno.land/std@0.201.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", - "https://deno.land/std@0.201.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", - "https://deno.land/std@0.201.0/assert/mod.ts": "37c49a26aae2b254bbe25723434dc28cd7532e444cf0b481a97c045d110ec085", - "https://deno.land/std@0.201.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", - "https://deno.land/std@0.201.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", - "https://deno.land/std@0.201.0/fmt/colors.ts": "87544aa2bc91087bb37f9c077970c85bfb041b48e4c37356129d7b450a415b6f", - "https://deno.land/std@0.201.0/testing/asserts.ts": "b4e4b1359393aeff09e853e27901a982c685cb630df30426ed75496961931946" + "https://deno.land/x/base64@v0.2.1/base.ts": "47dc8d68f07dc91524bdd6db36eccbe59cf4d935b5fc09f27357a3944bb3ff7b", + "https://deno.land/x/base64@v0.2.1/base64url.ts": "18bbf879b31f1f32cca8adaa2b6885ae325c2cec6a66c5817b684ca12c46ad5e", + "https://deno.land/x/base64@v0.2.1/mod.ts": "1cbdc4ba7229d3c6d1763fecdb9d46844777c7e153abb6dabea8b0dd01448db4", + "https://denopkg.com/chiefbiiko/sha256@v1.0.0/mod.ts": "eca3d13a2cd11839e451055737ccde0c7c6cdbd331fcd0a8f7e954ee857bb13a", + "https://denopkg.com/chiefbiiko/std-encoding@master/mod.ts": "e61017da4cef146863d614a961b4e61f1df14b72c906092bd02161f913e76522" } } diff --git a/lib/blake3-js/src/blake3_benches.ts b/lib/blake3-js/src/blake3_benches.ts new file mode 100644 index 000000000..cfe5b1bb2 --- /dev/null +++ b/lib/blake3-js/src/blake3_benches.ts @@ -0,0 +1,51 @@ +import { hash } from "./blake3.ts"; +import { hash as wasmHash } from "../../blake3-wasm/pkg/blake3_wasm.js"; +import { sha256 } from "https://denopkg.com/chiefbiiko/sha256@v1.0.0/mod.ts"; + +const SIZE: [string, number][] = [ + ["0B", 0], + ["32B", 32], + ["48B", 48], + ["96B", 96], + ["128B", 128], + ["256B", 256], + ["512B", 512], + ["1Kib", 1 * 1024], + ["8Kib", 8 * 1024], + ["16Kib", 16 * 1024], + ["32Kib", 32 * 1024], + ["64Kib", 64 * 1024], + ["128Kib", 128 * 1024], + ["256Kib", 256 * 1024], + ["512Kib", 512 * 1024], + ["1MB", 1024 * 1024], + ["100MB", 100 * 1024 * 1024], +]; + +for (const [group, size] of SIZE) { + const input = new Uint8Array(size); + + Deno.bench({ + name: `Sha256 ${group}`, + group, + fn() { + sha256(input); + }, + }); + + Deno.bench({ + name: `Optimized ${group}`, + group, + fn() { + hash(input); + }, + }); + + Deno.bench({ + name: `WASM ${group}`, + group, + fn() { + wasmHash(input); + }, + }); +}