feature. See also
. The project being documented here (as the example) is the Zig library itself.
benchmark.main
pub fn main(init: std.process.Init) !void
File
Code
pub fn main(init: std.process.Init) !void {
const io = init.io;
const arena = init.arena.allocator();
var stdout_buffer: [0x100]u8 = undefined;
var stdout_writer = Io.File.stdout().writer(io, &stdout_buffer);
const stdout = &stdout_writer.interface;
const args = try init.minimal.args.toSlice(arena);
var filter: ?[]const u8 = null;
var count: usize = mode(128 * MiB);
var bench_prngs = true;
var bench_csprngs = true;
var bench_long = true;
var bench_short = true;
var i: usize = 1;
while (i < args.len) : (i += 1) {
if (std.mem.eql(u8, args[i], "--mode")) {
try stdout.print("{}\n", .{builtin.mode});
try stdout.flush();
return;
} else if (std.mem.eql(u8, args[i], "--filter")) {
i += 1;
if (i == args.len) {
usage();
std.process.exit(1);
}
filter = args[i];
} else if (std.mem.eql(u8, args[i], "--count")) {
i += 1;
if (i == args.len) {
usage();
std.process.exit(1);
}
const c = try std.fmt.parseUnsigned(usize, args[i], 10);
count = c * MiB;
} else if (std.mem.eql(u8, args[i], "--csprngs-only")) {
bench_prngs = false;
} else if (std.mem.eql(u8, args[i], "--prngs-only")) {
bench_csprngs = false;
} else if (std.mem.eql(u8, args[i], "--short-only")) {
bench_long = false;
} else if (std.mem.eql(u8, args[i], "--long-only")) {
bench_short = false;
} else if (std.mem.eql(u8, args[i], "--help")) {
usage();
return;
} else {
usage();
std.process.exit(1);
}
}
if (bench_prngs) {
if (bench_long) {
inline for (prngs) |R| {
if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
try stdout.print("{s} (long outputs)\n", .{R.name});
try stdout.flush();
const result_long = try benchmark(R, io, count, long_block_size);
try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});
}
}
}
if (bench_short) {
inline for (prngs) |R| {
if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
try stdout.print("{s} (short outputs)\n", .{R.name});
try stdout.flush();
const result_short = try benchmark(R, io, count, short_block_size);
try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});
}
}
}
}
if (bench_csprngs) {
if (bench_long) {
inline for (csprngs) |R| {
if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
try stdout.print("{s} (cryptographic, long outputs)\n", .{R.name});
try stdout.flush();
const result_long = try benchmark(R, io, count, long_block_size);
try stdout.print(" {:5} MiB/s\n", .{result_long.throughput / (1 * MiB)});
}
}
}
if (bench_short) {
inline for (csprngs) |R| {
if (filter == null or std.mem.find(u8, R.name, filter.?) != null) {
try stdout.print("{s} (cryptographic, short outputs)\n", .{R.name});
try stdout.flush();
const result_short = try benchmark(R, io, count, short_block_size);
try stdout.print(" {:5} MiB/s\n", .{result_short.throughput / (1 * MiB)});
}
}
}
}
try stdout.flush();
}