2018-01-17 06:25:00 +00:00
|
|
|
// Modify the HashFunction variable to the one wanted to test.
|
|
|
|
//
|
|
|
|
// ```
|
2018-04-24 12:54:27 +01:00
|
|
|
// zig build-exe --release-fast throughput_test.zig
|
2018-01-17 06:25:00 +00:00
|
|
|
// ./throughput_test
|
|
|
|
// ```
|
|
|
|
|
|
|
|
const std = @import("std");
|
2018-04-24 12:54:27 +01:00
|
|
|
const time = std.os.time;
|
|
|
|
const Timer = time.Timer;
|
2018-04-20 07:42:52 +01:00
|
|
|
const HashFunction = @import("md5.zig").Md5;
|
2018-01-17 06:25:00 +00:00
|
|
|
|
2018-04-20 07:54:18 +01:00
|
|
|
const MiB = 1024 * 1024;
|
2018-05-26 23:16:39 +01:00
|
|
|
const BytesToHash = 1024 * MiB;
|
2018-01-17 06:25:00 +00:00
|
|
|
|
2018-02-01 03:48:40 +00:00
|
|
|
pub fn main() !void {
|
2018-01-17 06:25:00 +00:00
|
|
|
var stdout_file = try std.io.getStdOut();
|
2018-07-09 22:21:20 +01:00
|
|
|
var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
|
|
|
|
const stdout = &stdout_out_stream.stream;
|
2018-01-17 06:25:00 +00:00
|
|
|
|
|
|
|
var block: [HashFunction.block_size]u8 = undefined;
|
|
|
|
std.mem.set(u8, block[0..], 0);
|
|
|
|
|
|
|
|
var h = HashFunction.init();
|
|
|
|
var offset: usize = 0;
|
|
|
|
|
2018-04-24 12:54:27 +01:00
|
|
|
var timer = try Timer.start();
|
|
|
|
const start = timer.lap();
|
2018-01-17 06:25:00 +00:00
|
|
|
while (offset < BytesToHash) : (offset += block.len) {
|
|
|
|
h.update(block[0..]);
|
|
|
|
}
|
2018-04-24 12:54:27 +01:00
|
|
|
const end = timer.read();
|
2018-01-17 06:25:00 +00:00
|
|
|
|
2018-07-09 22:21:20 +01:00
|
|
|
const elapsed_s = @intToFloat(f64, end - start) / time.ns_per_s;
|
|
|
|
const throughput = @floatToInt(u64, BytesToHash / elapsed_s);
|
2018-01-17 06:25:00 +00:00
|
|
|
|
2018-04-20 07:54:18 +01:00
|
|
|
try stdout.print("{}: {} MiB/s\n", @typeName(HashFunction), throughput / (1 * MiB));
|
2018-01-17 06:25:00 +00:00
|
|
|
}
|