aboutsummaryrefslogtreecommitdiff
path: root/benches/leet.rs
blob: ef3b6494358351593a3967c8eebafa01ecbfad6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
mod mock_hashers;

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use passwordmaker_rs::{HashAlgorithm, LeetLevel};
use mock_hashers::Pwm;

fn criterion_bench_16bytes_post_leet(c: &mut Criterion) {
    let pwm = Pwm::new(
        HashAlgorithm::Md5, 
        passwordmaker_rs::UseLeetWhenGenerating::After { level: LeetLevel::Six },
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
        "",
        "",
        150,
        "",
        ""
    ).unwrap();
    c.bench_function("16 bytes with post_leet", |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_pre_leet(c: &mut Criterion) {
    let pwm = Pwm::new(
        HashAlgorithm::Md5, 
        passwordmaker_rs::UseLeetWhenGenerating::Before { level: LeetLevel::Six },
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
        "",
        "",
        150,
        "",
        ""
    ).unwrap();
    c.bench_function("16 bytes with pre_leet", |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_16bytes_post_leet,
    criterion_bench_16bytes_pre_leet
);
criterion_main!(benches);