zig/std/crypto/throughput_test.zig
Andrew Kelley 3671582c15 syntax: functions require return type. remove ->
The purpose of this is:

 * Only one way to do things
 * Changing a function with void return type to return a possible
   error becomes a 1 character change, subtly encouraging
   people to use errors.

See #632

Here are some imperfect sed commands for performing this update:

remove arrow:

```
sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig")
```

add void:

```
sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig")
```

Some cleanup may be necessary, but this should do the bulk of the work.
2018-01-25 04:10:11 -05:00

44 lines
1.2 KiB
Zig

// 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
// ./throughput_test
// ```
const HashFunction = @import("md5.zig").Md5;
const BytesToHash = 1024 * Mb;
const std = @import("std");
const c = @cImport({
@cInclude("time.h");
});
const Mb = 1024 * 1024;
pub fn main() %void {
var stdout_file = try std.io.getStdOut();
var stdout_out_stream = std.io.FileOutStream.init(&stdout_file);
const stdout = &stdout_out_stream.stream;
var block: [HashFunction.block_size]u8 = undefined;
std.mem.set(u8, block[0..], 0);
var h = HashFunction.init();
var offset: usize = 0;
const start = c.clock();
while (offset < BytesToHash) : (offset += block.len) {
h.update(block[0..]);
}
const end = c.clock();
const elapsed_s = f64((end - start) * c.CLOCKS_PER_SEC) / 1000000;
const throughput = u64(BytesToHash / elapsed_s);
try stdout.print("{}: ", @typeName(HashFunction));
try stdout.print("{} Mb/s\n", throughput);
}