mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
crypto throughput test now uses os.time module
This commit is contained in:
parent
15bf0c1541
commit
0501e066b5
@ -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;
|
||||
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user