Zig 0.17.0-dev (Split by item)
This is an example of documentation generated by
ZigDoc , an alternative to Zig's built-in
Auto Doc feature. See also
examples in other modes/formats . The project being documented here (as the example) is the Zig library itself.
Zig › std/ › Random/ › benchmark.zig › benchmark
benchmark
benchmark.benchmark
pub fn benchmark (comptime H : anytype , io : Io , bytes : usize , comptime block_size : usize ) !Result
File
Code
pub fn benchmark (comptime H : anytype , io : Io , bytes : usize , comptime block_size : usize ) !Result {
var rng = blk : {
if (H .init_u8s ) |init | {
break :blk H .ty .init (init [0 ..].*);
}
if (H .init_u64 ) |init | {
break :blk H .ty .init (init );
}
break :blk H .ty .init ();
};
var block : [block_size ]u8 = undefined ;
var offset : usize = 0 ;
const start = benchTime (io );
while (offset < bytes ) : (offset += block .len ) {
rng .fill (block [0 ..]);
}
const end = benchTime (io );
const elapsed_s = @as (f64 , @floatFromInt (end - start )) / time .ns_per_s ;
const throughput = @as (u64 , @intFromFloat (@as (f64 , @floatFromInt (bytes )) / elapsed_s ));
std .debug .assert (rng .random ().int (u64 ) != 0 );
return Result {
.throughput = throughput ,
};
}