diff options
author | Andreas Grois <andi@grois.info> | 2022-10-20 21:42:07 +0200 |
---|---|---|
committer | Andreas Grois <andi@grois.info> | 2022-10-20 21:42:07 +0200 |
commit | ea6789e5b33540270f5de3edb54264e6892fad73 (patch) | |
tree | 886f78169e328bc172dfdb79d171f2f20b7bc8e6 /benches/hashrate_32.rs | |
parent | bc9bd89c17dc41d9b1434866ac2d522070f46597 (diff) |
Group Benchmarks, and make parameters more sane.
The previous parameters for benchmarks were based on gut-feeling.
Now each hash-length has 3 benchmarks:
- Typical is a typical user input
- Max Divisions is a full generate_password_part run
- Worst Case is the worst user input possible: Base 2.
Diffstat (limited to 'benches/hashrate_32.rs')
-rw-r--r-- | benches/hashrate_32.rs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/benches/hashrate_32.rs b/benches/hashrate_32.rs new file mode 100644 index 0000000..7638add --- /dev/null +++ b/benches/hashrate_32.rs @@ -0,0 +1,69 @@ +mod mock_hashers; + +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use passwordmaker_rs::HashAlgorithm; +use mock_hashers::Pwm; + +fn criterion_bench_32bytes_typical(c: &mut Criterion) { + let pwm = Pwm::new( + HashAlgorithm::Sha256, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./", + "", + "", + 12, + "", + "" + ).unwrap(); + c.bench_function("32 bytes 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_32bytes_full_divide(c: &mut Criterion) { + let pwm = Pwm::new( + HashAlgorithm::Sha256, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./", + "", + "", + 40, + "", + "" + ).unwrap(); + c.bench_function("32 bytes 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_32bytes_worst_case(c: &mut Criterion) { + let pwm = Pwm::new( + HashAlgorithm::Sha256, + passwordmaker_rs::UseLeetWhenGenerating::NotAtAll, + "XY", + "", + "", + 256, + "", + "" + ).unwrap(); + c.bench_function("32 bytes 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!(benches, + criterion_bench_32bytes_typical, + criterion_bench_32bytes_full_divide, + criterion_bench_32bytes_worst_case, +); +criterion_main!(benches); |