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 {...@@ -157,9 +157,11 @@ fn usage() void {
157 \\throughput_test [options]157 \\throughput_test [options]
158 \\158 \\
159 \\Options:159 \\Options:
160 \\ --filter [test-name]160 \\ --filter [test-name]
161 \\ --seed [int]161 \\ --seed [int]
162 \\ --count [int]162 \\ --count [int]
163 \\ --key-size [int]
164 \\ --iterative-only
163 \\ --help165 \\ --help
164 \\166 \\
165 );167 );
...@@ -191,6 +193,7 @@ pub fn main() !void {...@@ -191,6 +193,7 @@ pub fn main() !void {
191 var count: usize = mode(128 * MiB);193 var count: usize = mode(128 * MiB);
192 var key_size: usize = 32;194 var key_size: usize = 32;
193 var seed: u32 = 0;195 var seed: u32 = 0;
196 var test_iterative_only = false;
194197
195 var i: usize = 1;198 var i: usize = 1;
196 while (i < args.len) : (i += 1) {199 while (i < args.len) : (i += 1) {
...@@ -235,6 +238,8 @@ pub fn main() !void {...@@ -235,6 +238,8 @@ pub fn main() !void {
235 try stdout.print("key_size cannot exceed block size of {}\n", block_size);238 try stdout.print("key_size cannot exceed block size of {}\n", block_size);
236 std.os.exit(1);239 std.os.exit(1);
237 }240 }
241 } else if (std.mem.eql(u8, args[i], "--iterative-only")) {
242 test_iterative_only = true;
238 } else if (std.mem.eql(u8, args[i], "--help")) {243 } else if (std.mem.eql(u8, args[i], "--help")) {
239 usage();244 usage();
240 return;245 return;
...@@ -246,19 +251,23 @@ pub fn main() !void {...@@ -246,19 +251,23 @@ pub fn main() !void {
246251
247 inline for (hashes) |H| {252 inline for (hashes) |H| {
248 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {253 if (filter == null or std.mem.indexOf(u8, H.name, filter.?) != null) {
249 try stdout.print("{}\n", H.name);254 if (!test_iterative_only or H.has_iterative_api) {
250255 try stdout.print("{}\n", H.name);
251 // Always reseed prior to every call so we are hashing the same buffer contents.256
252 // This allows easier comparison between different implementations.257 // Always reseed prior to every call so we are hashing the same buffer contents.
253 if (H.has_iterative_api) {258 // This allows easier comparison between different implementations.
254 prng.seed(seed);259 if (H.has_iterative_api) {
255 const result = try benchmarkHash(H, count);260 prng.seed(seed);
256 try stdout.print(" iterative: {:4} MiB/s [{x:0<16}]\n", result.throughput / (1 * MiB), result.hash);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 }
257 }270 }
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);
262 }271 }
263 }272 }
264}273}