aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--benches/hashrate.rs75
-rw-r--r--src/passwordmaker/base_conversion/remainders_impl.rs8
2 files changed, 74 insertions, 9 deletions
diff --git a/benches/hashrate.rs b/benches/hashrate.rs
index 2bb0f97..9691410 100644
--- a/benches/hashrate.rs
+++ b/benches/hashrate.rs
@@ -57,7 +57,7 @@ impl HasherList for MockHashes {
type Pwm<'a> = PasswordMaker<'a, MockHashes>;
-fn criterion_bench_32bit(c: &mut Criterion) {
+fn criterion_bench_32bytes(c: &mut Criterion) {
let pwm = Pwm::new(
HashAlgorithm::Sha256,
passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
@@ -76,7 +76,45 @@ fn criterion_bench_32bit(c: &mut Criterion) {
}));
}
-fn criterion_bench_16bit(c: &mut Criterion) {
+fn criterion_bench_32bytes_extreme(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Sha256,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "XY",
+ "",
+ "",
+ 150,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("32 bytes extreme", |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_20bytes(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Ripemd160,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 150,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("20 bytes", |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(c: &mut Criterion) {
let pwm = Pwm::new(
HashAlgorithm::Md5,
passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
@@ -95,7 +133,26 @@ fn criterion_bench_16bit(c: &mut Criterion) {
}));
}
-fn criterion_bench_16bit_post_leet(c: &mut Criterion) {
+fn criterion_bench_16bytes_extreme(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "XY",
+ "",
+ "",
+ 150,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes extreme", |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_post_leet(c: &mut Criterion) {
let pwm = Pwm::new(
HashAlgorithm::Md5,
passwordmaker_rs::UseLeetWhenGenerating::After { level: LeetLevel::Six },
@@ -114,7 +171,7 @@ fn criterion_bench_16bit_post_leet(c: &mut Criterion) {
}));
}
-fn criterion_bench_16bit_pre_leet(c: &mut Criterion) {
+fn criterion_bench_16bytes_pre_leet(c: &mut Criterion) {
let pwm = Pwm::new(
HashAlgorithm::Md5,
passwordmaker_rs::UseLeetWhenGenerating::Before { level: LeetLevel::Six },
@@ -133,5 +190,13 @@ fn criterion_bench_16bit_pre_leet(c: &mut Criterion) {
}));
}
-criterion_group!(benches, criterion_bench_32bit, criterion_bench_16bit, criterion_bench_16bit_post_leet, criterion_bench_16bit_pre_leet);
+criterion_group!(benches,
+ criterion_bench_32bytes,
+ criterion_bench_32bytes_extreme,
+ criterion_bench_20bytes,
+ criterion_bench_16bytes,
+ criterion_bench_16bytes_extreme,
+ criterion_bench_16bytes_post_leet,
+ criterion_bench_16bytes_pre_leet
+);
criterion_main!(benches);
diff --git a/src/passwordmaker/base_conversion/remainders_impl.rs b/src/passwordmaker/base_conversion/remainders_impl.rs
index 7de2189..7bc6c0e 100644
--- a/src/passwordmaker/base_conversion/remainders_impl.rs
+++ b/src/passwordmaker/base_conversion/remainders_impl.rs
@@ -9,20 +9,20 @@ impl<const N : usize> Division<usize> for [u32;N] {
type UsizeAndFour = u128;
#[cfg(not(target_pointer_width = "64"))]
type UsizeAndFour = u64;
- assert!((UsizeAndFour::MAX >> 32) as u128 >= usize::MAX as u128);
+ debug_assert!((UsizeAndFour::MAX >> 32) as u128 >= usize::MAX as u128);
//uses mutation, because why not? self is owned after all :D
let divisor : UsizeAndFour = *divisor as UsizeAndFour;
let remainder = self.iter_mut().fold(0 as UsizeAndFour,|carry, current| {
- assert_eq!(carry, carry & (usize::MAX as UsizeAndFour)); //carry has to be lower than divisor, and divisor is usize.
+ debug_assert_eq!(carry, carry & (usize::MAX as UsizeAndFour)); //carry has to be lower than divisor, and divisor is usize.
let carry_shifted = carry << 32;
let dividend = (carry_shifted) + (*current as UsizeAndFour);
let ratio = dividend / divisor;
- assert_eq!(ratio, ratio & 0xffff_ffff); //this is fine. The first digit after re-adding the carry is alwys zero.
+ debug_assert_eq!(ratio, ratio & 0xffff_ffff); //this is fine. The first digit after re-adding the carry is alwys zero.
*current = (ratio) as u32;
dividend - (*current as UsizeAndFour) * divisor
});
- assert_eq!(remainder, remainder & (usize::MAX as UsizeAndFour));
+ debug_assert_eq!(remainder, remainder & (usize::MAX as UsizeAndFour));
let remainder = remainder as usize;
DivisionResult{
result: self,