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 @@...@@ -1,17 +1,13 @@
1// Modify the HashFunction variable to the one wanted to test.1// Modify the HashFunction variable to the one wanted to test.
2//2//
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//
6// ```3// ```
7// zig build-exe --release-fast --library c throughput_test.zig4// zig build-exe --release-fast throughput_test.zig
8// ./throughput_test5// ./throughput_test
9// ```6// ```
107
11const std = @import("std");8const std = @import("std");
12const c = @cImport({9const time = std.os.time;
13 @cInclude("time.h");10const Timer = time.Timer;
14});
15const HashFunction = @import("md5.zig").Md5;11const HashFunction = @import("md5.zig").Md5;
1612
17const MiB = 1024 * 1024;13const MiB = 1024 * 1024;
...@@ -28,13 +24,14 @@ pub fn main() !void {...@@ -28,13 +24,14 @@ pub fn main() !void {
28 var h = HashFunction.init();24 var h = HashFunction.init();
29 var offset: usize = 0;25 var offset: usize = 0;
3026
31 const start = c.clock();27 var timer = try Timer.start();
28 const start = timer.lap();
32 while (offset < BytesToHash) : (offset += block.len) {29 while (offset < BytesToHash) : (offset += block.len) {
33 h.update(block[0..]);30 h.update(block[0..]);
34 }31 }
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;
38 const throughput = u64(BytesToHash / elapsed_s);35 const throughput = u64(BytesToHash / elapsed_s);
3936
40 try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB));37 try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB));