authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-04-24 23:54:27+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2018-04-24 23:54:27+12:00
log0501e066b51b659371739008c20e80642532497a
treeee4522fff537551875441551a374eb9e86a68482
parent15bf0c1541479870dff1f8d64a3746c337f901ef

crypto throughput test now uses os.time module


1 files changed, 7 insertions(+), 10 deletions(-)

std/crypto/throughput_test.zig+7-10
......@@ -1,17 +1,13 @@
11// Modify the HashFunction variable to the one wanted to test.
22//
3// NOTE: The throughput measurement may be slightly lower than other measurements since we run
4// through our block alignment functions as well. Be aware when comparing against other tests.
5//
63// ```
7// zig build-exe --release-fast --library c throughput_test.zig
4// zig build-exe --release-fast throughput_test.zig
85// ./throughput_test
96// ```
107
118const std = @import("std");
12const c = @cImport({
13 @cInclude("time.h");
14});
9const time = std.os.time;
10const Timer = time.Timer;
1511const HashFunction = @import("md5.zig").Md5;
1612
1713const MiB = 1024 * 1024;
......@@ -28,13 +24,14 @@ pub fn main() !void {
2824 var h = HashFunction.init();
2925 var offset: usize = 0;
3026
31 const start = c.clock();
27 var timer = try Timer.start();
28 const start = timer.lap();
3229 while (offset < BytesToHash) : (offset += block.len) {
3330 h.update(block[0..]);
3431 }
35 const end = c.clock();
32 const end = timer.read();
3633
37 const elapsed_s = f64(end - start) / f64(c.CLOCKS_PER_SEC);
34 const elapsed_s = f64(end - start) / time.ns_per_s;
3835 const throughput = u64(BytesToHash / elapsed_s);
3936
4037 try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB));