use key_vault::{KeyVaultBuilder, RawKey};
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
const ITERATIONS: usize = 100_000;
const KEY_LEN: usize = 32;
fn main() {
let _profiler = dhat::Profiler::new_heap();
let vault = KeyVaultBuilder::new().normalize_with_blake3(false).build();
let key: Vec<u8> = (0..KEY_LEN).map(|i| (i as u8).wrapping_mul(7)).collect();
let handle = vault.register("hot", RawKey::new(key)).expect("register");
for _ in 0..1_000 {
let _: u32 = vault
.with_key(handle, |bytes| {
bytes
.iter()
.copied()
.fold(0u32, |a, b| a.wrapping_add(u32::from(b)))
})
.expect("with_key");
}
for _ in 0..ITERATIONS {
let _: u32 = vault
.with_key(handle, |bytes| {
bytes
.iter()
.copied()
.fold(0u32, |a, b| a.wrapping_add(u32::from(b)))
})
.expect("with_key");
}
println!(
"dhat_hot_path: ran {ITERATIONS} with_key iterations on a {KEY_LEN}-byte key. \
See dhat-heap.json for the allocation profile."
);
}