Skip to content

Commit

Permalink
migrate one test to criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
radumarias committed Nov 22, 2024
1 parent 4701f28 commit d9b56c7
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions benches/crypto_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,27 @@ fn bench_read_1mb_chacha_file(c: &mut Criterion) {
});
}

// #[bench]
// fn bench_read_1mb_aes_file(b: &mut Bencher) {
// use crate::crypto;
// use crate::crypto::write::CryptoWrite;
// use crate::crypto::Cipher;
// use rand::RngCore;
// use shush_rs::SecretVec;
// use std::io;
// use std::io::Seek;
// use test::black_box;
//
// let cipher = Cipher::Aes256Gcm;
// let len = 1024 * 1024;
//
// let mut key: Vec<u8> = vec![0; cipher.key_len()];
// rand::thread_rng().fill_bytes(&mut key);
// let key = SecretVec::new(Box::new(key));
//
// let file = tempfile::tempfile().unwrap();
// let mut writer = crypto::create_write(file, cipher, &key);
// let mut cursor_random = io::Cursor::new(vec![0; len]);
// rand::thread_rng().fill_bytes(cursor_random.get_mut());
// cursor_random.seek(io::SeekFrom::Start(0)).unwrap();
// io::copy(&mut cursor_random, &mut writer).unwrap();
// let file = writer.finish().unwrap();
//
// b.iter(|| {
// black_box({
// let mut file = file.try_clone().unwrap();
// file.seek(io::SeekFrom::Start(0)).unwrap();
// let mut reader = crypto::create_read(file, cipher, &key);
// io::copy(&mut reader, &mut io::sink()).unwrap()
// });
// });
// }
//
fn bench_read_1mb_aes_file(c: &mut Criterion) {
let cipher = Cipher::Aes256Gcm;
let len = 1024 * 1024;

let mut key: Vec<u8> = vec![0; cipher.key_len()];
rand::thread_rng().fill_bytes(&mut key);
let key = SecretVec::new(Box::new(key));

c.bench_function("bench_read_1mb_chacha_file", |b| {
b.iter(|| {
let file = tempfile::tempfile().unwrap();
let mut writer = crypto::create_write(file, cipher, &key);
let mut cursor_random = io::Cursor::new(vec![0; len]);
rand::thread_rng().fill_bytes(cursor_random.get_mut());
cursor_random.seek(io::SeekFrom::Start(0)).unwrap();
io::copy(&mut cursor_random, &mut writer).unwrap();
black_box(writer.finish().unwrap())
})
});
}

// #[bench]
// fn bench_read_1mb_chacha_ram(b: &mut Bencher) {
// use crate::crypto;
Expand Down Expand Up @@ -141,5 +126,5 @@ fn bench_read_1mb_chacha_file(c: &mut Criterion) {
// });
// }

criterion_group!(benches, bench_read_1mb_chacha_file);
criterion_group!(benches, bench_read_1mb_chacha_file, gs);
criterion_main!(benches);

0 comments on commit d9b56c7

Please sign in to comment.