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 {
133133
134134 const args = try init.minimal.args.toSlice(arena);
135135
136 var filter: ?[]u8 = "";
136 var filter: ?[]const u8 = null;
137137 var count: usize = mode(128 * MiB);
138138 var bench_prngs = true;
139139 var bench_csprngs = true;
lib/std/crypto/benchmark.zig+27-23
......@@ -173,9 +173,9 @@ const signatures = [_]Crypto{
173173 Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" },
174174};
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 {
177177 const msg = [_]u8{0} ** 64;
178 const key_pair = Signature.KeyPair.generate();
178 const key_pair = Signature.KeyPair.generate(io);
179179
180180 var timer = try Timer.start();
181181 const start = timer.lap();
......@@ -201,9 +201,9 @@ const signature_verifications = [_]Crypto{
201201 Crypto{ .ty = crypto.sign.mldsa.MLDSA87, .name = "ml-dsa-87" },
202202};
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 {
205205 const msg = [_]u8{0} ** 64;
206 const key_pair = Signature.KeyPair.generate();
206 const key_pair = Signature.KeyPair.generate(io);
207207 const sig = try key_pair.sign(&msg, null);
208208
209209 var timer = try Timer.start();
......@@ -225,9 +225,9 @@ pub fn benchmarkSignatureVerification(comptime Signature: anytype, comptime sign
225225
226226const 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 {
229229 const msg = [_]u8{0} ** 64;
230 const key_pair = Signature.KeyPair.generate();
230 const key_pair = Signature.KeyPair.generate(io);
231231 const sig = try key_pair.sign(&msg, null);
232232
233233 var batch: [64]Signature.BatchElement = undefined;
......@@ -240,7 +240,7 @@ pub fn benchmarkBatchSignatureVerification(comptime Signature: anytype, comptime
240240 {
241241 var i: usize = 0;
242242 while (i < signatures_count) : (i += 1) {
243 try Signature.verifyBatch(batch.len, batch);
243 try Signature.verifyBatch(io, batch.len, batch);
244244 mem.doNotOptimizeAway(&sig);
245245 }
246246 }
......@@ -258,15 +258,15 @@ const kems = [_]Crypto{
258258 Crypto{ .ty = crypto.kem.kyber_d00.Kyber1024, .name = "kyber1024d00" },
259259};
260260
261pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 {
262 const key_pair = Kem.KeyPair.generate();
261pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 {
262 const key_pair = Kem.KeyPair.generate(io);
263263
264264 var timer = try Timer.start();
265265 const start = timer.lap();
266266 {
267267 var i: usize = 0;
268268 while (i < kems_count) : (i += 1) {
269 const e = key_pair.public_key.encaps(null);
269 const e = key_pair.public_key.encaps(io);
270270 mem.doNotOptimizeAway(&e);
271271 }
272272 }
......@@ -278,10 +278,10 @@ pub fn benchmarkKem(comptime Kem: anytype, comptime kems_count: comptime_int) !u
278278 return throughput;
279279}
280280
281pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_int) !u64 {
282 const key_pair = Kem.KeyPair.generate();
281pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_int, io: std.Io) !u64 {
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
286286 var timer = try Timer.start();
287287 const start = timer.lap();
......@@ -300,13 +300,13 @@ pub fn benchmarkKemDecaps(comptime Kem: anytype, comptime kems_count: comptime_i
300300 return throughput;
301301}
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 {
304304 var timer = try Timer.start();
305305 const start = timer.lap();
306306 {
307307 var i: usize = 0;
308308 while (i < kems_count) : (i += 1) {
309 const key_pair = Kem.KeyPair.generate();
309 const key_pair = Kem.KeyPair.generate(io);
310310 mem.doNotOptimizeAway(&key_pair);
311311 }
312312 }
......@@ -464,7 +464,9 @@ fn benchmarkPwhash(
464464
465465 const strHash = ty.strHash;
466466 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
469471 var timer = try Timer.start();
470472 const start = timer.lap();
......@@ -473,6 +475,8 @@ fn benchmarkPwhash(
473475 while (i < count) : (i += 1) {
474476 if (needs_io) {
475477 _ = try strHash(password, opts, &buf, io);
478 } else if (needs_salt) {
479 _ = try strHash(password, opts, &buf, &salt);
476480 } else {
477481 _ = try strHash(password, opts, &buf);
478482 }
......@@ -514,7 +518,7 @@ pub fn main(init: std.process.Init) !void {
514518
515519 const args = try init.minimal.args.toSlice(arena);
516520
517 var filter: ?[]u8 = "";
521 var filter: ?[]const u8 = null;
518522
519523 var i: usize = 1;
520524 while (i < args.len) : (i += 1) {
......@@ -582,7 +586,7 @@ pub fn main(init: std.process.Init) !void {
582586
583587 inline for (signatures) |E| {
584588 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);
586590 try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });
587591 try stdout.flush();
588592 }
......@@ -590,7 +594,7 @@ pub fn main(init: std.process.Init) !void {
590594
591595 inline for (signature_verifications) |E| {
592596 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);
594598 try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });
595599 try stdout.flush();
596600 }
......@@ -598,7 +602,7 @@ pub fn main(init: std.process.Init) !void {
598602
599603 inline for (batch_signature_verifications) |E| {
600604 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);
602606 try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });
603607 try stdout.flush();
604608 }
......@@ -638,7 +642,7 @@ pub fn main(init: std.process.Init) !void {
638642
639643 inline for (kems) |E| {
640644 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);
642646 try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });
643647 try stdout.flush();
644648 }
......@@ -646,7 +650,7 @@ pub fn main(init: std.process.Init) !void {
646650
647651 inline for (kems) |E| {
648652 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);
650654 try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });
651655 try stdout.flush();
652656 }
......@@ -654,7 +658,7 @@ pub fn main(init: std.process.Init) !void {
654658
655659 inline for (kems) |E| {
656660 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);
658662 try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });
659663 try stdout.flush();
660664 }
lib/std/hash/benchmark.zig+1-1
......@@ -363,7 +363,7 @@ pub fn main(init: std.process.Init) !void {
363363
364364 const args = try init.minimal.args.toSlice(arena);
365365
366 var filter: ?[]u8 = "";
366 var filter: ?[]const u8 = null;
367367 var count: usize = mode(128 * MiB);
368368 var key_size: ?usize = null;
369369 var seed: u32 = 0;