aboutsummaryrefslogtreecommitdiff
path: root/benches/hashrate_16_hmac.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2023-01-20 00:16:57 +0100
committerAndreas Grois <andi@grois.info>2023-01-20 00:16:57 +0100
commitad1c6728521a2a89ee790cd12baaea73aa6041a2 (patch)
tree78078875d0168f69aa51e596bcd073c5b93b943f /benches/hashrate_16_hmac.rs
parent26b9bc316d8db76b7840f5598877590310a9f49f (diff)
Add benchmark for HMAC code.
Also, simplify the function a bit. It's faster this way, even though there's an additional unconditional collect() call now.
Diffstat (limited to 'benches/hashrate_16_hmac.rs')
-rw-r--r--benches/hashrate_16_hmac.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/benches/hashrate_16_hmac.rs b/benches/hashrate_16_hmac.rs
new file mode 100644
index 0000000..9a8deb7
--- /dev/null
+++ b/benches/hashrate_16_hmac.rs
@@ -0,0 +1,73 @@
+mod mock_hashers;
+
+use std::time::Duration;
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use passwordmaker_rs::HashAlgorithm;
+use mock_hashers::Pwm;
+
+fn criterion_bench_16bytes_hmac_typical(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::HmacMd5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 12,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes HMAC typical", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_16bytes_hmac_full_divide(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::HmacMd5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 20,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes HMAC full divide", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_16bytes_hmac_worst_case(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::HmacMd5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "XY",
+ "",
+ "",
+ 128,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes HMAC worst case", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+criterion_group!(name = benches;
+ // This can be any expression that returns a `Criterion` object.
+ config = Criterion::default().significance_level(0.02).sample_size(500).measurement_time(Duration::from_secs(10));
+ targets = criterion_bench_16bytes_hmac_typical,
+ criterion_bench_16bytes_hmac_full_divide,
+ criterion_bench_16bytes_hmac_worst_case,
+);
+criterion_main!(benches);