]>
git.proxmox.com Git - proxmox-backup.git/blob - examples/cipherbench.rs
5 fn rate_test(name
: &str, bench
: &dyn Fn() -> usize) {
7 print
!("{:<20} ", name
);
9 let start
= std
::time
::SystemTime
::now();
10 let duration
= std
::time
::Duration
::new(1, 0);
16 let elapsed
= start
.elapsed().unwrap();
17 if elapsed
> duration { break; }
20 let elapsed
= start
.elapsed().unwrap();
21 let elapsed
= (elapsed
.as_secs() as f64) +
22 (elapsed
.subsec_millis() as f64)/1000.0;
24 println
!("{:>8.1} MB/s", (bytes
as f64)/(elapsed
*1024.0*1024.0));
28 fn main() -> Result
<(), Error
> {
30 let input
= proxmox
::sys
::linux
::random_data(1024*1024)?
;
32 rate_test("crc32", &|| {
33 let mut crchasher
= crc32fast
::Hasher
::new();
34 crchasher
.update(&input
);
35 let _checksum
= crchasher
.finalize();
39 rate_test("zstd", &|| {
40 zstd
::block
::compress(&input
, 1).unwrap();
44 rate_test("sha256", &|| {
45 openssl
::sha
::sha256(&input
);
49 let key
= proxmox
::sys
::linux
::random_data(32)?
;
51 let iv
= proxmox
::sys
::linux
::random_data(16)?
;
53 let cipher
= openssl
::symm
::Cipher
::aes_256_gcm();
55 rate_test("aes-256-gcm", &|| {
56 let mut tag
= [0u8;16];
57 openssl
::symm
::encrypt_aead(
67 let cipher
= openssl
::symm
::Cipher
::chacha20_poly1305();
69 rate_test("chacha20-poly1305", &|| {
70 let mut tag
= [0u8;16];
71 openssl
::symm
::encrypt_aead(