From b41b35f5789f39ef12d07997a74a7dc35224538c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matheus=20C=2E=20Fran=C3=A7a?= Date: Thu, 20 Oct 2022 08:04:59 -0300 Subject: [PATCH] crypto/benchmark - replace testing allocator Fix error: Cannot use testing allocator outside of test block --- lib/std/crypto/benchmark.zig | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/std/crypto/benchmark.zig b/lib/std/crypto/benchmark.zig index ddc5bc1b1d..28d283048a 100644 --- a/lib/std/crypto/benchmark.zig +++ b/lib/std/crypto/benchmark.zig @@ -317,12 +317,13 @@ const pwhashes = [_]CryptoPwhash{ }; fn benchmarkPwhash( + allocator: mem.Allocator, comptime ty: anytype, comptime params: *const anyopaque, comptime count: comptime_int, ) !f64 { const password = "testpass" ** 2; - const opts = .{ .allocator = std.testing.allocator, .params = @ptrCast(*const ty.Params, params).*, .encoding = .phc }; + const opts = .{ .allocator = allocator, .params = @ptrCast(*const ty.Params, params).*, .encoding = .phc }; var buf: [256]u8 = undefined; var timer = try Timer.start(); @@ -361,9 +362,10 @@ fn mode(comptime x: comptime_int) comptime_int { pub fn main() !void { const stdout = std.io.getStdOut().writer(); - var buffer: [1024]u8 = undefined; - var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); - const args = try std.process.argsAlloc(fixed.allocator()); + var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); + defer arena.deinit(); + const arena_allocator = arena.allocator(); + const args = try std.process.argsAlloc(arena_allocator); var filter: ?[]u8 = ""; @@ -463,7 +465,7 @@ pub fn main() !void { inline for (pwhashes) |H| { if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) { - const throughput = try benchmarkPwhash(H.ty, H.params, mode(64)); + const throughput = try benchmarkPwhash(arena_allocator, H.ty, H.params, mode(64)); try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput }); } }