feature. See also
. The project being documented here (as the example) is the Zig library itself.
benchmark.benchmarkHashSmallKeysArrayPtr
pub fn benchmarkHashSmallKeysArrayPtr(
comptime H: anytype,
comptime key_size: usize,
bytes: usize,
allocator: std.mem.Allocator,
io: Io,
) !Result
File
Code
pub fn benchmarkHashSmallKeysArrayPtr(
comptime H: anytype,
comptime key_size: usize,
bytes: usize,
allocator: std.mem.Allocator,
io: Io,
) !Result {
var blocks = try allocator.alloc(u8, bytes);
defer allocator.free(blocks);
random.bytes(blocks);
const key_count = bytes / key_size;
const start = benchTime(io);
var sum: u64 = 0;
for (0..key_count) |i| {
const small_key = blocks[i * key_size ..][0..key_size];
const final: u64 = blk: {
if (H.init_u8s) |init| {
if (H.has_crypto_api) {
break :blk @truncate(H.ty.toInt(small_key, init[0..H.ty.key_length]));
} else {
break :blk H.ty.hash(init, small_key);
}
}
if (H.init_u64) |init| {
break :blk H.ty.hash(init, small_key);
}
break :blk H.ty.hash(small_key);
};
sum +%= final;
}
const elapsed_ns = benchTime(io) - start;
const elapsed_s = @as(f64, @floatFromInt(elapsed_ns)) / time.ns_per_s;
const throughput: u64 = @intFromFloat(@as(f64, @floatFromInt(bytes)) / elapsed_s);
std.mem.doNotOptimizeAway(sum);
return Result{
.hash = sum,
.throughput = throughput,
};
}