mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 22:33:08 +00:00
crypto/benchmark - replace testing allocator
Fix error: Cannot use testing allocator outside of test block
This commit is contained in:
parent
a99d465f62
commit
b41b35f578
@ -317,12 +317,13 @@ const pwhashes = [_]CryptoPwhash{
|
|||||||
};
|
};
|
||||||
|
|
||||||
fn benchmarkPwhash(
|
fn benchmarkPwhash(
|
||||||
|
allocator: mem.Allocator,
|
||||||
comptime ty: anytype,
|
comptime ty: anytype,
|
||||||
comptime params: *const anyopaque,
|
comptime params: *const anyopaque,
|
||||||
comptime count: comptime_int,
|
comptime count: comptime_int,
|
||||||
) !f64 {
|
) !f64 {
|
||||||
const password = "testpass" ** 2;
|
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 buf: [256]u8 = undefined;
|
||||||
|
|
||||||
var timer = try Timer.start();
|
var timer = try Timer.start();
|
||||||
@ -361,9 +362,10 @@ fn mode(comptime x: comptime_int) comptime_int {
|
|||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
const stdout = std.io.getStdOut().writer();
|
const stdout = std.io.getStdOut().writer();
|
||||||
|
|
||||||
var buffer: [1024]u8 = undefined;
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]);
|
defer arena.deinit();
|
||||||
const args = try std.process.argsAlloc(fixed.allocator());
|
const arena_allocator = arena.allocator();
|
||||||
|
const args = try std.process.argsAlloc(arena_allocator);
|
||||||
|
|
||||||
var filter: ?[]u8 = "";
|
var filter: ?[]u8 = "";
|
||||||
|
|
||||||
@ -463,7 +465,7 @@ pub fn main() !void {
|
|||||||
|
|
||||||
inline for (pwhashes) |H| {
|
inline for (pwhashes) |H| {
|
||||||
if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
|
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 });
|
try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user