feat: works

This commit is contained in:
2023-10-22 00:42:30 +08:00
parent 745b192c20
commit 71b8f75417
7 changed files with 427 additions and 481 deletions

38
examples/bench.rs Normal file
View File

@@ -0,0 +1,38 @@
use benchmark_simple::{Bench, Options};
fn test_chacha20_poly1305_encrypt(m: &mut [u8]) {
let key = [0u8; 32];
let nonce = [0u8; 12];
chacha20_poly1305_stream::chacha20_poly1305_encrypt(&key, &nonce, m).unwrap();
}
fn test_chacha20_poly1305_encrypt_and_decrypt(m: &mut [u8]) {
let key = [0u8; 32];
let nonce = [0u8; 12];
let encrypted = chacha20_poly1305_stream::chacha20_poly1305_encrypt(&key, &nonce, m).unwrap();
let decrypted = chacha20_poly1305_stream::chacha20_poly1305_decrypt(&key, &nonce, &encrypted).unwrap();
assert_eq!(m, decrypted.as_slice());
}
fn main() {
let bench = Bench::new();
let mut m = vec![0xd0u8; 16384];
let options = &Options {
iterations: 1_000,
warmup_iterations: 1_00,
min_samples: 5,
max_samples: 10,
max_rsd: 1.0,
..Default::default()
};
let res = bench.run(options, || test_chacha20_poly1305_encrypt(&mut m));
println!("ChaCha20Poly1305 encrypt : {}", res.throughput(m.len() as _));
let res = bench.run(options, || test_chacha20_poly1305_encrypt_and_decrypt(&mut m));
println!("ChaCha20Poly1305 encrypt/decrypt : {}", res.throughput(m.len() as _));
}