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{...@@ -317,12 +317,13 @@ const pwhashes = [_]CryptoPwhash{
317};317};
318318
319fn benchmarkPwhash(319fn benchmarkPwhash(
320 allocator: mem.Allocator,
320 comptime ty: anytype,321 comptime ty: anytype,
321 comptime params: *const anyopaque,322 comptime params: *const anyopaque,
322 comptime count: comptime_int,323 comptime count: comptime_int,
323) !f64 {324) !f64 {
324 const password = "testpass" ** 2;325 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 };
326 var buf: [256]u8 = undefined;327 var buf: [256]u8 = undefined;
327328
328 var timer = try Timer.start();329 var timer = try Timer.start();
...@@ -361,9 +362,10 @@ fn mode(comptime x: comptime_int) comptime_int {...@@ -361,9 +362,10 @@ fn mode(comptime x: comptime_int) comptime_int {
361pub fn main() !void {362pub fn main() !void {
362 const stdout = std.io.getStdOut().writer();363 const stdout = std.io.getStdOut().writer();
363364
364 var buffer: [1024]u8 = undefined;365 var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
365 var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);366 defer arena.deinit();
366 const args = try std.process.argsAlloc(fixed.allocator());367 const arena_allocator = arena.allocator();
368 const args = try std.process.argsAlloc(arena_allocator);
367369
368 var filter: ?[]u8 = "";370 var filter: ?[]u8 = "";
369371
...@@ -463,7 +465,7 @@ pub fn main() !void {...@@ -463,7 +465,7 @@ pub fn main() !void {
463465
464 inline for (pwhashes) |H| {466 inline for (pwhashes) |H| {
465 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {467 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));
467 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });469 try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
468 }470 }
469 }471 }