authorgravatar for matheus-catarino@hotmail.comMatheus C. França <matheus-catarino@hotmail.com> 2022-10-20 08:04:59-03:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-10-20 14:04:59+03:00
logb41b35f5789f39ef12d07997a74a7dc35224538c
treed2d7a3e992b896f3c0711b9574eb427c402dcea7
parenta99d465f624d9cdd82d270e03dd931c0539df8d7
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

crypto/benchmark - replace testing allocator

Fix error: Cannot use testing allocator outside of test block

1 files changed, 7 insertions(+), 5 deletions(-)

lib/std/crypto/benchmark.zig+7-5
......@@ -317,12 +317,13 @@ const pwhashes = [_]CryptoPwhash{
317317};
318318
319319fn benchmarkPwhash(
320 allocator: mem.Allocator,
320321 comptime ty: anytype,
321322 comptime params: *const anyopaque,
322323 comptime count: comptime_int,
323324) !f64 {
324325 const password = "testpass" ** 2;
325 const opts = .{ .allocator = std.testing.allocator, .params = @ptrCast(*const ty.Params, params).*, .encoding = .phc };
326 const opts = .{ .allocator = allocator, .params = @ptrCast(*const ty.Params, params).*, .encoding = .phc };
326327 var buf: [256]u8 = undefined;
327328
328329 var timer = try Timer.start();
......@@ -361,9 +362,10 @@ fn mode(comptime x: comptime_int) comptime_int {
361362pub fn main() !void {
362363 const stdout = std.io.getStdOut().writer();
363364
364 var buffer: [1024]u8 = undefined;
365 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
366 const args = try std.process.argsAlloc(fixed.allocator());
365 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
366 defer arena.deinit();
367 const arena_allocator = arena.allocator();
368 const args = try std.process.argsAlloc(arena_allocator);
367369
368370 var filter: ?[]u8 = "";
369371
......@@ -463,7 +465,7 @@ pub fn main() !void {
463465
464466 inline for (pwhashes) |H| {
465467 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
466 const throughput = try benchmarkPwhash(H.ty, H.params, mode(64));
468 const throughput = try benchmarkPwhash(arena_allocator, H.ty, H.params, mode(64));
467469 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
468470 }
469471 }