authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2026-01-07 23:02:49+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-13 07:04:51+01:00
logbe84d7cb9bdbf8a1a4212f10c1dfdc437af0532c
tree78e1cdfd09d134f45808107f8f78267e9b1d37a3
parentd86e8b7795a5b5c2403c6a07dc818bc1d8a5cda4

Fix benchmarks after the randomness changes


3 files changed, 29 insertions(+), 25 deletions(-)

lib/std/Random/benchmark.zig+1-1
...@@ -133,7 +133,7 @@ pub fn main(init: std.process.Init) !void {...@@ -133,7 +133,7 @@ pub fn main(init: std.process.Init) !void {
133133
134 const args = try init.minimal.args.toSlice(arena);134 const args = try init.minimal.args.toSlice(arena);
135135
136 var filter: ?[]u8 = "";136 var filter: ?[]const u8 = null;
137 var count: usize = mode(128 * MiB);137 var count: usize = mode(128 * MiB);
138 var bench_prngs = true;138 var bench_prngs = true;
139 var bench_csprngs = true;139 var bench_csprngs = true;
lib/std/crypto/benchmark.zig+27-23
...@@ -173,9 +173,9 @@ const signatures = [_]Crypto{...@@ -173,9 +173,9 @@ const signatures = [_]Crypto{
173 Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" },173 Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" },
174};174};
175175
176pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 {176pub fn benchmarkSignature(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 {
177 const msg = [_]u8{0} ** 64;177 const msg = [_]u8{0} ** 64;
178 const key_pair = Signature.KeyPair.generate();178 const key_pair = Signature.KeyPair.generate(io);
179179
180 var timer = try Timer.start();180 var timer = try Timer.start();
181 const start = timer.lap();181 const start = timer.lap();
...@@ -201,9 +201,9 @@ const signature_verifications = [_]Crypto{...@@ -201,9 +201,9 @@ const signature_verifications = [_]Crypto{
201 Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" },201 Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" },
202};202};
203203
204pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 {204pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 {
205 const msg = [_]u8{0} ** 64;205 const msg = [_]u8{0} ** 64;
206 const key_pair = Signature.KeyPair.generate();206 const key_pair = Signature.KeyPair.generate(io);
207 const sig = try key_pair.sign(&msg, null);207 const sig = try key_pair.sign(&msg, null);
208208
209 var timer = try Timer.start();209 var timer = try Timer.start();
...@@ -225,9 +225,9 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign...@@ -225,9 +225,9 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign
225225
226const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }};226const batch_signature_verifications = [_]Crypto{Crypto{ .ty = crypto.sign.Ed25519, .name = "ed25519" }};
227227
228pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int) !u64 {228pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime signatures_count: comptime_int, io: std.Io) !u64 {
229 const msg = [_]u8{0} ** 64;229 const msg = [_]u8{0} ** 64;
230 const key_pair = Signature.KeyPair.generate();230 const key_pair = Signature.KeyPair.generate(io);
231 const sig = try key_pair.sign(&msg, null);231 const sig = try key_pair.sign(&msg, null);
232232
233 var batch: [64]Signature.BatchElement = undefined;233 var batch: [64]Signature.BatchElement = undefined;
...@@ -240,7 +240,7 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime...@@ -240,7 +240,7 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime
240 {240 {
241 var i: usize = 0;241 var i: usize = 0;
242 while (i < signatures_count) : (i += 1) {242 while (i < signatures_count) : (i += 1) {
243 try Signature.verifyBatch(batch.len, batch);243 try Signature.verifyBatch(io, batch.len, batch);
244 mem.doNotOptimizeAway(&sig);244 mem.doNotOptimizeAway(&sig);
245 }245 }
246 }246 }
...@@ -258,15 +258,15 @@ const kems = [_]Crypto{...@@ -258,15 +258,15 @@ const kems = [_]Crypto{
258 Crypto{ .ty = crypto.kem.kyber_d00.Kyber1024, .name = "kyber1024d00" },258 Crypto{ .ty = crypto.kem.kyber_d00.Kyber1024, .name = "kyber1024d00" },
259};259};
260260
261pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 {261pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 {
262 const key_pair = Kem.KeyPair.generate();262 const key_pair = Kem.KeyPair.generate(io);
263263
264 var timer = try Timer.start();264 var timer = try Timer.start();
265 const start = timer.lap();265 const start = timer.lap();
266 {266 {
267 var i: usize = 0;267 var i: usize = 0;
268 while (i < kems_count) : (i += 1) {268 while (i < kems_count) : (i += 1) {
269 const e = key_pair.public_key.encaps(null);269 const e = key_pair.public_key.encaps(io);
270 mem.doNotOptimizeAway(&e);270 mem.doNotOptimizeAway(&e);
271 }271 }
272 }272 }
...@@ -278,10 +278,10 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u...@@ -278,10 +278,10 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u
278 return throughput;278 return throughput;
279}279}
280280
281pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 {281pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 {
282 const key_pair = Kem.KeyPair.generate();282 const key_pair = Kem.KeyPair.generate(io);
283283
284 const e = key_pair.public_key.encaps(null);284 const e = key_pair.public_key.encaps(io);
285285
286 var timer = try Timer.start();286 var timer = try Timer.start();
287 const start = timer.lap();287 const start = timer.lap();
...@@ -300,13 +300,13 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i...@@ -300,13 +300,13 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i
300 return throughput;300 return throughput;
301}301}
302302
303pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 {303pub fn benchmarkKemKeyGen(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 {
304 var timer = try Timer.start();304 var timer = try Timer.start();
305 const start = timer.lap();305 const start = timer.lap();
306 {306 {
307 var i: usize = 0;307 var i: usize = 0;
308 while (i < kems_count) : (i += 1) {308 while (i < kems_count) : (i += 1) {
309 const key_pair = Kem.KeyPair.generate();309 const key_pair = Kem.KeyPair.generate(io);
310 mem.doNotOptimizeAway(&key_pair);310 mem.doNotOptimizeAway(&key_pair);
311 }311 }
312 }312 }
...@@ -464,7 +464,9 @@ fn benchmarkPwhash(...@@ -464,7 +464,9 @@ fn benchmarkPwhash(
464464
465 const strHash = ty.strHash;465 const strHash = ty.strHash;
466 const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn";466 const strHashFnInfo = @typeInfo(@TypeOf(strHash)).@"fn";
467 const needs_io = strHashFnInfo.params.len == 4;467 const needs_io = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type == std.Io;
468 const needs_salt = strHashFnInfo.params.len == 4 and strHashFnInfo.params[3].type != std.Io;
469 const salt: [16]u8 = .{0} ** 16;
468470
469 var timer = try Timer.start();471 var timer = try Timer.start();
470 const start = timer.lap();472 const start = timer.lap();
...@@ -473,6 +475,8 @@ fn benchmarkPwhash(...@@ -473,6 +475,8 @@ fn benchmarkPwhash(
473 while (i < count) : (i += 1) {475 while (i < count) : (i += 1) {
474 if (needs_io) {476 if (needs_io) {
475 _ = try strHash(password, opts, &buf, io);477 _ = try strHash(password, opts, &buf, io);
478 } else if (needs_salt) {
479 _ = try strHash(password, opts, &buf, &salt);
476 } else {480 } else {
477 _ = try strHash(password, opts, &buf);481 _ = try strHash(password, opts, &buf);
478 }482 }
...@@ -514,7 +518,7 @@ pub fn main(init: std.process.Init) !void {...@@ -514,7 +518,7 @@ pub fn main(init: std.process.Init) !void {
514518
515 const args = try init.minimal.args.toSlice(arena);519 const args = try init.minimal.args.toSlice(arena);
516520
517 var filter: ?[]u8 = "";521 var filter: ?[]const u8 = null;
518522
519 var i: usize = 1;523 var i: usize = 1;
520 while (i < args.len) : (i += 1) {524 while (i < args.len) : (i += 1) {
...@@ -582,7 +586,7 @@ pub fn main(init: std.process.Init) !void {...@@ -582,7 +586,7 @@ pub fn main(init: std.process.Init) !void {
582586
583 inline for (signatures) |E| {587 inline for (signatures) |E| {
584 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {588 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
585 const throughput = try benchmarkSignature(E.ty, mode(1000));589 const throughput = try benchmarkSignature(E.ty, mode(1000), io);
586 try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });590 try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });
587 try stdout.flush();591 try stdout.flush();
588 }592 }
...@@ -590,7 +594,7 @@ pub fn main(init: std.process.Init) !void {...@@ -590,7 +594,7 @@ pub fn main(init: std.process.Init) !void {
590594
591 inline for (signature_verifications) |E| {595 inline for (signature_verifications) |E| {
592 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {596 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
593 const throughput = try benchmarkSignatureVerification(E.ty, mode(1000));597 const throughput = try benchmarkSignatureVerification(E.ty, mode(1000), io);
594 try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });598 try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });
595 try stdout.flush();599 try stdout.flush();
596 }600 }
...@@ -598,7 +602,7 @@ pub fn main(init: std.process.Init) !void {...@@ -598,7 +602,7 @@ pub fn main(init: std.process.Init) !void {
598602
599 inline for (batch_signature_verifications) |E| {603 inline for (batch_signature_verifications) |E| {
600 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {604 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
601 const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000));605 const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000), io);
602 try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });606 try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });
603 try stdout.flush();607 try stdout.flush();
604 }608 }
...@@ -638,7 +642,7 @@ pub fn main(init: std.process.Init) !void {...@@ -638,7 +642,7 @@ pub fn main(init: std.process.Init) !void {
638642
639 inline for (kems) |E| {643 inline for (kems) |E| {
640 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {644 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
641 const throughput = try benchmarkKem(E.ty, mode(1000));645 const throughput = try benchmarkKem(E.ty, mode(1000), io);
642 try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });646 try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });
643 try stdout.flush();647 try stdout.flush();
644 }648 }
...@@ -646,7 +650,7 @@ pub fn main(init: std.process.Init) !void {...@@ -646,7 +650,7 @@ pub fn main(init: std.process.Init) !void {
646650
647 inline for (kems) |E| {651 inline for (kems) |E| {
648 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {652 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
649 const throughput = try benchmarkKemDecaps(E.ty, mode(25000));653 const throughput = try benchmarkKemDecaps(E.ty, mode(25000), io);
650 try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });654 try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });
651 try stdout.flush();655 try stdout.flush();
652 }656 }
...@@ -654,7 +658,7 @@ pub fn main(init: std.process.Init) !void {...@@ -654,7 +658,7 @@ pub fn main(init: std.process.Init) !void {
654658
655 inline for (kems) |E| {659 inline for (kems) |E| {
656 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {660 if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
657 const throughput = try benchmarkKemKeyGen(E.ty, mode(25000));661 const throughput = try benchmarkKemKeyGen(E.ty, mode(25000), io);
658 try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });662 try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });
659 try stdout.flush();663 try stdout.flush();
660 }664 }
lib/std/hash/benchmark.zig+1-1
...@@ -363,7 +363,7 @@ pub fn main(init: std.process.Init) !void {...@@ -363,7 +363,7 @@ pub fn main(init: std.process.Init) !void {
363363
364 const args = try init.minimal.args.toSlice(arena);364 const args = try init.minimal.args.toSlice(arena);
365365
366 var filter: ?[]u8 = "";366 var filter: ?[]const u8 = null;
367 var count: usize = mode(128 * MiB);367 var count: usize = mode(128 * MiB);
368 var key_size: ?usize = null;368 var key_size: ?usize = null;
369 var seed: u32 = 0;369 var seed: u32 = 0;