| ... | ... | @@ -1,17 +1,13 @@ |
| 1 | 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.zig |
| 4 | // zig build-exe --release-fast throughput_test.zig |
| 8 | 5 | // ./throughput_test |
| 9 | 6 | // ``` |
| 10 | 7 | |
| 11 | 8 | const std = @import("std"); |
| 12 | | const c = @cImport({ |
| 13 | | @cInclude("time.h"); |
| 14 | | }); |
| 9 | const time = std.os.time; |
| 10 | const Timer = time.Timer; |
| 15 | 11 | const HashFunction = @import("md5.zig").Md5; |
| 16 | 12 | |
| 17 | 13 | const MiB = 1024 * 1024; |
| ... | ... | @@ -28,13 +24,14 @@ pub fn main() !void { |
| 28 | 24 | var h = HashFunction.init(); |
| 29 | 25 | var offset: usize = 0; |
| 30 | 26 | |
| 31 | | const start = c.clock(); |
| 27 | var timer = try Timer.start(); |
| 28 | const start = timer.lap(); |
| 32 | 29 | while (offset < BytesToHash) : (offset += block.len) { |
| 33 | 30 | h.update(block[0..]); |
| 34 | 31 | } |
| 35 | | const end = c.clock(); |
| 32 | const end = timer.read(); |
| 36 | 33 | |
| 37 | | const elapsed_s = f64(end - start) / f64(c.CLOCKS_PER_SEC); |
| 34 | const elapsed_s = f64(end - start) / time.ns_per_s; |
| 38 | 35 | const throughput = u64(BytesToHash / elapsed_s); |
| 39 | 36 | |
| 40 | 37 | try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB)); |