crypto throughput test now uses os.time module

This commit is contained in:
Marc Tiehuis 2018-04-24 23:54:27 +12:00
parent 15bf0c1541
commit 0501e066b5

View File

@ -1,17 +1,13 @@
// Modify the HashFunction variable to the one wanted to test. // Modify the HashFunction variable to the one wanted to test.
// //
// NOTE: The throughput measurement may be slightly lower than other measurements since we run
// through our block alignment functions as well. Be aware when comparing against other tests.
//
// ``` // ```
// zig build-exe --release-fast --library c throughput_test.zig // zig build-exe --release-fast throughput_test.zig
// ./throughput_test // ./throughput_test
// ``` // ```
const std = @import("std"); const std = @import("std");
const c = @cImport({ const time = std.os.time;
@cInclude("time.h"); const Timer = time.Timer;
});
const HashFunction = @import("md5.zig").Md5; const HashFunction = @import("md5.zig").Md5;
const MiB = 1024 * 1024; const MiB = 1024 * 1024;
@ -28,13 +24,14 @@ pub fn main() !void {
var h = HashFunction.init(); var h = HashFunction.init();
var offset: usize = 0; var offset: usize = 0;
const start = c.clock(); var timer = try Timer.start();
const start = timer.lap();
while (offset < BytesToHash) : (offset += block.len) { while (offset < BytesToHash) : (offset += block.len) {
h.update(block[0..]); h.update(block[0..]);
} }
const end = c.clock(); const end = timer.read();
const elapsed_s = f64(end - start) / f64(c.CLOCKS_PER_SEC); const elapsed_s = f64(end - start) / time.ns_per_s;
const throughput = u64(BytesToHash / elapsed_s); const throughput = u64(BytesToHash / elapsed_s);
try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB)); try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB));