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/ › crypto/ › benchmark.zig › benchmarkKeyExchange
benchmarkKeyExchange
benchmark.benchmarkKeyExchange
pub fn benchmarkKeyExchange (comptime DhKeyExchange : anytype , comptime exchange_count : comptime_int , io : Io ) !u64
File
Code
pub fn benchmarkKeyExchange (comptime DhKeyExchange : anytype , comptime exchange_count : comptime_int , io : Io ) !u64 {
std .debug .assert (DhKeyExchange .shared_length >= DhKeyExchange .secret_length );
var secret : [DhKeyExchange .shared_length ]u8 = undefined ;
random .bytes (secret [0 ..]);
var public : [DhKeyExchange .shared_length ]u8 = undefined ;
random .bytes (public [0 ..]);
const start = benchTime (io );
{
var i : usize = 0 ;
while (i < exchange_count ) : (i += 1 ) {
const out = try DhKeyExchange .scalarmult (secret , public );
secret [0 ..16 ].* = out [0 ..16 ].*;
public [0 ..16 ].* = out [16 ..32 ].*;
mem .doNotOptimizeAway (&out );
}
}
const end = benchTime (io );
const elapsed_s = @as (f64 , @floatFromInt (end - start )) / time .ns_per_s ;
const throughput = @as (u64 , @intFromFloat (exchange_count / elapsed_s ));
return throughput ;
}