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 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], "--seed")) {
i += 1;
if (i == args.len) {
usage();
std.process.exit(1);
}
const seed = try std.fmt.parseUnsigned(u32, args[i], 10);
prng.seed(seed);
} 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], "--help")) {
usage();
return;
} else {
usage();
std.process.exit(1);
}
}
inline for (hashes) |H| {
if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
const throughput = try benchmarkHash(H.ty, mode(128 * MiB), io);
try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
try stdout.flush();
}
}
inline for (parallel_hashes) |H| {
if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
const throughput = try benchmarkHashParallel(H.ty, mode(128 * MiB), arena, io);
try stdout.print("{s:>17}: {:10} MiB/s\n", .{ H.name, throughput / (1 * MiB) });
try stdout.flush();
}
}
inline for (macs) |M| {
if (filter == null or std.mem.find(u8, M.name, filter.?) != null) {
const throughput = try benchmarkMac(M.ty, mode(128 * MiB), io);
try stdout.print("{s:>17}: {:10} MiB/s\n", .{ M.name, throughput / (1 * MiB) });
try stdout.flush();
}
}
inline for (exchanges) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKeyExchange(E.ty, mode(1000), io);
try stdout.print("{s:>17}: {:10} exchanges/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (signatures) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkSignature(E.ty, mode(1000), io);
try stdout.print("{s:>17}: {:10} signatures/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (signature_verifications) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkSignatureVerification(E.ty, mode(1000), io);
try stdout.print("{s:>17}: {:10} verifications/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (batch_signature_verifications) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkBatchSignatureVerification(E.ty, mode(1000), io);
try stdout.print("{s:>17}: {:10} verifications/s (batch)\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (aeads) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkAead(E.ty, mode(128 * MiB), io);
try stdout.print("{s:>17}: {:10} MiB/s\n", .{ E.name, throughput / (1 * MiB) });
try stdout.flush();
}
}
inline for (aes) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkAes(E.ty, mode(100000000), io);
try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (aes8) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkAes8(E.ty, mode(10000000), io);
try stdout.print("{s:>17}: {:10} ops/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (pwhashes) |H| {
if (filter == null or std.mem.find(u8, H.name, filter.?) != null) {
const throughput = try benchmarkPwhash(arena, H.ty, H.params, mode(64), io);
try stdout.print("{s:>17}: {d:10.3} s/ops\n", .{ H.name, throughput });
try stdout.flush();
}
}
inline for (kems) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKem(E.ty, mode(1000), io);
try stdout.print("{s:>17}: {:10} encaps/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (kems) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKemDecaps(E.ty, mode(25000), io);
try stdout.print("{s:>17}: {:10} decaps/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
inline for (kems) |E| {
if (filter == null or std.mem.find(u8, E.name, filter.?) != null) {
const throughput = try benchmarkKemKeyGen(E.ty, mode(25000), io);
try stdout.print("{s:>17}: {:10} keygen/s\n", .{ E.name, throughput });
try stdout.flush();
}
}
}