mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
optimize test_ct_intlog2 test and whirlpool hash (#2938)
* optimize `test_ct_intlog2` while still covering all 128 bit positions * refactor whirlpool to reduce code bloat replaced the fully unrolled round loop with a runtime loop, reducing instruction count by 80k in `process_block` and yielding aprox 30% performance boost due to improved cache locality. * use compile-time arrays for `test_ct_intlog2`
This commit is contained in:
57
benchmarks/stdlib/hash/whirlpool.c3
Normal file
57
benchmarks/stdlib/hash/whirlpool.c3
Normal file
@@ -0,0 +1,57 @@
|
||||
module whirlpool_bench;
|
||||
|
||||
fn void initialize_bench() @init
|
||||
{
|
||||
set_benchmark_warmup_iterations(3);
|
||||
set_benchmark_max_iterations(128);
|
||||
|
||||
input = mem::alloc_array(char, BUFSZ);
|
||||
input[:BUFSZ] = (char[]){ [0..BUFSZ-1] = 0xA5 }[..];
|
||||
input_slice = input[:BUFSZ];
|
||||
}
|
||||
|
||||
fn void teardown_bench() @finalizer
|
||||
{
|
||||
mem::free(input);
|
||||
input = null;
|
||||
}
|
||||
|
||||
char* input;
|
||||
char[] input_slice;
|
||||
const usz BUFSZ = 1024 * 1024;
|
||||
|
||||
module whirlpool_bench @benchmark;
|
||||
|
||||
import std::hash;
|
||||
|
||||
fn void whirlpool_hash()
|
||||
{
|
||||
runtime::@start_benchmark();
|
||||
char[*] myset = whirlpool::hash(input_slice);
|
||||
runtime::@end_benchmark();
|
||||
mem::zero_volatile(myset[..]);
|
||||
}
|
||||
|
||||
fn void compared_with_sha256()
|
||||
{
|
||||
runtime::@start_benchmark();
|
||||
char[*] myset = sha256::hash(input_slice);
|
||||
runtime::@end_benchmark();
|
||||
mem::zero_volatile(myset[..]);
|
||||
}
|
||||
|
||||
fn void compared_with_sha512()
|
||||
{
|
||||
runtime::@start_benchmark();
|
||||
char[*] myset = sha512::hash(input_slice);
|
||||
runtime::@end_benchmark();
|
||||
mem::zero_volatile(myset[..]);
|
||||
}
|
||||
|
||||
fn void compared_with_streebog_512()
|
||||
{
|
||||
runtime::@start_benchmark();
|
||||
char[*] myset = streebog::hash_512(input_slice);
|
||||
runtime::@end_benchmark();
|
||||
mem::zero_volatile(myset[..]);
|
||||
}
|
||||
Reference in New Issue
Block a user