INNER CODE UNIT · Rust
len
xoriors/rencfs · benches/crypto_read.rs:12
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();
c.bench_function("bench_read_1mb_chacha_file", |b| {
b.iter(|| {
let mut file = file.try_clone().unwrap();
file.seek(io::SeekFrom::Start(0)).unwrap();