From 4701f28d669acfe573448619e0b6273d4662f904 Mon Sep 17 00:00:00 2001 From: Radu Marias Date: Fri, 22 Nov 2024 18:31:00 +0200 Subject: [PATCH] migrate one test to criterion --- Cargo.lock | 251 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 5 + benches/crypto_read.rs | 145 ++++++++++++++++++++++ java-bridge/Cargo.lock | 223 ++++++++++++++++++++++++++++++++++ src/crypto/read.rs | 1 - src/crypto/read/bench.rs | 146 ----------------------- 6 files changed, 624 insertions(+), 147 deletions(-) create mode 100644 benches/crypto_read.rs delete mode 100644 src/crypto/read/bench.rs diff --git a/Cargo.lock b/Cargo.lock index ae3d31b..1f1cd04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -43,6 +43,12 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstream" version = "0.6.15" @@ -483,6 +489,12 @@ version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cbc" version = "0.1.2" @@ -525,6 +537,33 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "cipher" version = "0.4.4" @@ -630,6 +669,42 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -639,12 +714,37 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -1002,6 +1102,16 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if 1.0.0", + "crunchy", +] + [[package]] name = "hashbrown" version = "0.15.0" @@ -1110,12 +1220,32 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1429,6 +1559,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "ordered-stream" version = "0.2.0" @@ -1508,6 +1644,34 @@ dependencies = [ "futures-io", ] +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "polling" version = "2.8.0" @@ -1612,6 +1776,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.7" @@ -1679,6 +1863,7 @@ dependencies = [ "bon", "bytes", "clap", + "criterion", "ctrlc", "fuse3", "futures-util", @@ -1806,6 +1991,21 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e819f2bc632f285be6d7cd36e25940d45b2391dd6d9b939e79de557f7014248" +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1880,6 +2080,18 @@ dependencies = [ "syn 2.0.79", ] +[[package]] +name = "serde_json" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.19" @@ -2126,6 +2338,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tokio" version = "1.40.0" @@ -2341,6 +2563,16 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2402,6 +2634,16 @@ version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" +[[package]] +name = "web-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "which" version = "6.0.3" @@ -2430,6 +2672,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index 792f568..0297956 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,10 +57,15 @@ thread_local = "1.1.8" subtle = "2.6.1" bon = "2.2.0" shush-rs = "0.1.10" +criterion = { version = "0.5.1", features = ["html_reports"] } [target.'cfg(target_os = "linux")'.dependencies] fuse3 = { version = "0.7.2", features = ["tokio-runtime", "unprivileged"] } +[[bench]] +name = "crypto_read" +harness = false + [profile.release] #panic = "abort" # Treat warnings as errors in release builds diff --git a/benches/crypto_read.rs b/benches/crypto_read.rs new file mode 100644 index 0000000..a9ad32c --- /dev/null +++ b/benches/crypto_read.rs @@ -0,0 +1,145 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use rand_core::RngCore; +use rencfs::crypto; +use rencfs::crypto::write::CryptoWrite; +use rencfs::crypto::Cipher; +use shush_rs::SecretVec; +use std::io; +use std::io::Seek; + +fn bench_read_1mb_chacha_file(c: &mut Criterion) { + let cipher = Cipher::ChaCha20Poly1305; + let len = 1024 * 1024; + + let mut key: Vec = 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(); + let mut reader = crypto::create_read(file, cipher, &key); + black_box(io::copy(&mut reader, &mut io::sink()).unwrap()) + }) + }); +} + +// #[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 = 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() +// }); +// }); +// } +// +// #[bench] +// fn bench_read_1mb_chacha_ram(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::ChaCha20Poly1305; +// let len = 1024 * 1024; +// +// let mut key: Vec = vec![0; cipher.key_len()]; +// rand::thread_rng().fill_bytes(&mut key); +// let key = SecretVec::new(Box::new(key)); +// +// let cursor_write = io::Cursor::new(vec![]); +// let mut writer = crypto::create_write(cursor_write, 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 cursor_write = writer.finish().unwrap(); +// +// b.iter(|| { +// black_box({ +// let mut cursor = cursor_write.clone(); +// cursor.seek(io::SeekFrom::Start(0)).unwrap(); +// let mut reader = crypto::create_read(cursor, cipher, &key); +// io::copy(&mut reader, &mut io::sink()).unwrap() +// }); +// }); +// } +// +// #[bench] +// fn bench_read_1mb_aes_ram(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 = vec![0; cipher.key_len()]; +// rand::thread_rng().fill_bytes(&mut key); +// let key = SecretVec::new(Box::new(key)); +// +// let cursor_write = io::Cursor::new(vec![]); +// let mut writer = crypto::create_write(cursor_write, 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 cursor_write = writer.finish().unwrap(); +// +// b.iter(|| { +// black_box({ +// let mut cursor = cursor_write.clone(); +// cursor.seek(io::SeekFrom::Start(0)).unwrap(); +// let mut reader = crypto::create_read(cursor, cipher, &key); +// io::copy(&mut reader, &mut io::sink()).unwrap() +// }); +// }); +// } + +criterion_group!(benches, bench_read_1mb_chacha_file); +criterion_main!(benches); diff --git a/java-bridge/Cargo.lock b/java-bridge/Cargo.lock index 5327da0..f180fc0 100644 --- a/java-bridge/Cargo.lock +++ b/java-bridge/Cargo.lock @@ -55,6 +55,12 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstream" version = "0.6.15" @@ -495,6 +501,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cbc" version = "0.1.2" @@ -534,6 +546,33 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" +[[package]] +name = "ciborium" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "cipher" version = "0.4.4" @@ -649,6 +688,42 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-channel" version = "0.5.13" @@ -658,12 +733,37 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + [[package]] name = "crypto-common" version = "0.1.6" @@ -1026,6 +1126,16 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "half" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if 1.0.0", + "crunchy", +] + [[package]] name = "hashbrown" version = "0.14.5" @@ -1133,12 +1243,32 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is-terminal" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +dependencies = [ + "hermit-abi 0.4.0", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.11" @@ -1476,6 +1606,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "oorandom" +version = "11.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" + [[package]] name = "ordered-stream" version = "0.2.0" @@ -1555,6 +1691,34 @@ dependencies = [ "futures-io", ] +[[package]] +name = "plotters" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" + +[[package]] +name = "plotters-svg" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" +dependencies = [ + "plotters-backend", +] + [[package]] name = "polling" version = "2.8.0" @@ -1659,6 +1823,26 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "redox_syscall" version = "0.5.3" @@ -1726,6 +1910,7 @@ dependencies = [ "bon", "bytes", "clap", + "criterion", "ctrlc", "fuse3", "futures-util", @@ -1853,6 +2038,12 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "same-file" version = "1.0.6" @@ -1936,6 +2127,18 @@ dependencies = [ "syn 2.0.72", ] +[[package]] +name = "serde_json" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "serde_repr" version = "0.1.19" @@ -2176,6 +2379,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tokio" version = "1.39.2" @@ -2461,6 +2674,16 @@ version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "which" version = "6.0.2" diff --git a/src/crypto/read.rs b/src/crypto/read.rs index 91ad1e3..7436815 100644 --- a/src/crypto/read.rs +++ b/src/crypto/read.rs @@ -13,7 +13,6 @@ use crate::crypto::buf_mut::BufMut; use crate::crypto::write::BLOCK_SIZE; use crate::stream_util; -mod bench; mod test; /// Reads encrypted content from the wrapped Reader. diff --git a/src/crypto/read/bench.rs b/src/crypto/read/bench.rs deleted file mode 100644 index 91b46a3..0000000 --- a/src/crypto/read/bench.rs +++ /dev/null @@ -1,146 +0,0 @@ -#[allow(unused_imports)] -use test::Bencher; - -#[bench] -fn bench_read_1mb_chacha_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::ChaCha20Poly1305; - let len = 1024 * 1024; - - let mut key: Vec = 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() - }); - }); -} - -#[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 = 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() - }); - }); -} - -#[bench] -fn bench_read_1mb_chacha_ram(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::ChaCha20Poly1305; - let len = 1024 * 1024; - - let mut key: Vec = vec![0; cipher.key_len()]; - rand::thread_rng().fill_bytes(&mut key); - let key = SecretVec::new(Box::new(key)); - - let cursor_write = io::Cursor::new(vec![]); - let mut writer = crypto::create_write(cursor_write, 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 cursor_write = writer.finish().unwrap(); - - b.iter(|| { - black_box({ - let mut cursor = cursor_write.clone(); - cursor.seek(io::SeekFrom::Start(0)).unwrap(); - let mut reader = crypto::create_read(cursor, cipher, &key); - io::copy(&mut reader, &mut io::sink()).unwrap() - }); - }); -} - -#[bench] -fn bench_read_1mb_aes_ram(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 = vec![0; cipher.key_len()]; - rand::thread_rng().fill_bytes(&mut key); - let key = SecretVec::new(Box::new(key)); - - let cursor_write = io::Cursor::new(vec![]); - let mut writer = crypto::create_write(cursor_write, 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 cursor_write = writer.finish().unwrap(); - - b.iter(|| { - black_box({ - let mut cursor = cursor_write.clone(); - cursor.seek(io::SeekFrom::Start(0)).unwrap(); - let mut reader = crypto::create_read(cursor, cipher, &key); - io::copy(&mut reader, &mut io::sink()).unwrap() - }); - }); -}