Skip to content

Commit

Permalink
crypto throughput test now uses os.time module
Browse files Browse the repository at this point in the history
  • Loading branch information
tiehuis committed Apr 24, 2018
1 parent 15bf0c1 commit 0501e06
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions std/crypto/throughput_test.zig
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// 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
// ```

const std = @import("std");
const c = @cImport({
@cInclude("time.h");
});
const time = std.os.time;
const Timer = time.Timer;
const HashFunction = @import("md5.zig").Md5;

const MiB = 1024 * 1024;
Expand All @@ -28,13 +24,14 @@ pub fn main() !void {
var h = HashFunction.init();
var offset: usize = 0;

const start = c.clock();
var timer = try Timer.start();
const start = timer.lap();
while (offset < BytesToHash) : (offset += block.len) {
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);

try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB));
Expand Down

0 comments on commit 0501e06

Please sign in to comment.