authorgravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2019-08-21 21:02:24+12:00
committergravatar for marc@tiehu.isMarc Tiehuis <marc@tiehu.is> 2019-08-21 21:02:24+12:00
log7854a52a6b8ba541e302c5466f61e0970e5d6062
tree0f24693c640f958e787dd06a13ff91b7706c4f11
parent48410943cbcbf53ae3c9895b2452218d6eacbc4b

Add iterative-only filter to hash benchmark


1 files changed, 24 insertions(+), 15 deletions(-)

std/hash/benchmark.zig+24-15
......@@ -157,9 +157,11 @@ fn usage() void {
157157 \\throughput_test [options]
158158 \\
159159 \\Options:
160 \\ --filter [test-name]
161 \\ --seed [int]
162 \\ --count [int]
160 \\ --filter [test-name]
161 \\ --seed [int]
162 \\ --count [int]
163 \\ --key-size [int]
164 \\ --iterative-only
163165 \\ --help
164166 \\
165167 );
......@@ -191,6 +193,7 @@ pub fn main() !void {
191193 var count: usize = mode(128 * MiB);
192194 var key_size: usize = 32;
193195 var seed: u32 = 0;
196 var test_iterative_only = false;
194197
195198 var i: usize = 1;
196199 while (i < args.len) : (i += 1) {
......@@ -235,6 +238,8 @@ pub fn main() !void {
235238 try stdout.print("key_size cannot exceed block size of {}\n", block_size);
236239 std.os.exit(1);
237240 }
241 } else if (std.mem.eql(u8, args[i], "--iterative-only")) {
242 test_iterative_only = true;
238243 } else if (std.mem.eql(u8, args[i], "--help")) {
239244 usage();
240245 return;
......@@ -246,19 +251,23 @@ pub fn main() !void {
246251
247252 inline for (hashes) |H| {
248253 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
249 try stdout.print("{}\n", H.name);
250
251 // Always reseed prior to every call so we are hashing the same buffer contents.
252 // This allows easier comparison between different implementations.
253 if (H.has_iterative_api) {
254 prng.seed(seed);
255 const result = try benchmarkHash(H, count);
256 try stdout.print(" iterative: {:4} MiB/s [{x:0<16}]\n", result.throughput / (1 * MiB), result.hash);
254 if (!test_iterative_only or H.has_iterative_api) {
255 try stdout.print("{}\n", H.name);
256
257 // Always reseed prior to every call so we are hashing the same buffer contents.
258 // This allows easier comparison between different implementations.
259 if (H.has_iterative_api) {
260 prng.seed(seed);
261 const result = try benchmarkHash(H, count);
262 try stdout.print(" iterative: {:4} MiB/s [{x:0<16}]\n", result.throughput / (1 * MiB), result.hash);
263 }
264
265 if (!test_iterative_only) {
266 prng.seed(seed);
267 const result_small = try benchmarkHashSmallKeys(H, key_size, count);
268 try stdout.print(" small keys: {:4} MiB/s [{x:0<16}]\n", result_small.throughput / (1 * MiB), result_small.hash);
269 }
257270 }
258
259 prng.seed(seed);
260 const result_small = try benchmarkHashSmallKeys(H, key_size, count);
261 try stdout.print(" small keys: {:4} MiB/s [{x:0<16}]\n", result_small.throughput / (1 * MiB), result_small.hash);
262271 }
263272 }
264273}