| ... | @@ -7,16 +7,15 @@ | ... | @@ -7,16 +7,15 @@ |
| 7 | // zig build-exe --release-fast --library c throughput_test.zig | 7 | // zig build-exe --release-fast --library c throughput_test.zig |
| 8 | // ./throughput_test | 8 | // ./throughput_test |
| 9 | // ``` | 9 | // ``` |
| 10 | const HashFunction = @import("md5.zig").Md5; | | |
| 11 | const BytesToHash = 1024 * Mb; | | |
| 12 | | 10 | |
| 13 | const std = @import("std"); | 11 | const std = @import("std"); |
| 14 | | | |
| 15 | const c = @cImport({ | 12 | const c = @cImport({ |
| 16 | @cInclude("time.h"); | 13 | @cInclude("time.h"); |
| 17 | }); | 14 | }); |
| | 15 | const HashFunction = @import("md5.zig").Md5; |
| 18 | | 16 | |
| 19 | const Mb = 1024 * 1024; | 17 | const MB = 1024 * 1024; |
| | 18 | const BytesToHash = 1024 * MB; |
| 20 | | 19 | |
| 21 | pub fn main() !void { | 20 | pub fn main() !void { |
| 22 | var stdout_file = try std.io.getStdOut(); | 21 | var stdout_file = try std.io.getStdOut(); |
| ... | @@ -35,9 +34,9 @@ pub fn main() !void { | ... | @@ -35,9 +34,9 @@ pub fn main() !void { |
| 35 | } | 34 | } |
| 36 | const end = c.clock(); | 35 | const end = c.clock(); |
| 37 | | 36 | |
| 38 | const elapsed_s = f64((end - start) * c.CLOCKS_PER_SEC) / 1000000; | 37 | const elapsed_s = f64(end - start) / f64(c.CLOCKS_PER_SEC); |
| 39 | const throughput = u64(BytesToHash / elapsed_s); | 38 | const throughput = u64(BytesToHash / elapsed_s); |
| 40 | | 39 | |
| 41 | try stdout.print("{}: ", @typeName(HashFunction)); | 40 | try stdout.print("{}: ", @typeName(HashFunction)); |
| 42 | try stdout.print("{} Mb/s\n", throughput); | 41 | try stdout.print("{} MB/s\n", throughput / (1 * MB)); |
| 43 | } | 42 | } |