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
#[macro_export]
macro_rules! benches {
    ($params:path) => {
        #[cfg(all(test, feature="bench"))]
        mod bench {
            #![allow(unused_qualifications, unused_imports)]
            extern crate test;

            use self::test::Bencher;

            use super::*;

            use ::hashing::Algorithm;

            #[bench]
            fn short(b: &mut Bencher) {
                let password = "hunter2*********".to_owned();
                let alg = Algorithm::Single(<$params>::default().into());
                println!("Bench params: {:?}", alg);
                b.iter(|| {
                    alg.hash(password.clone().into())
                })
            }

            #[bench]
            fn long(b: &mut Bencher) {
                let password = "hunter2".to_owned().repeat(10);
                println!("Password: {:?}", &password);
                let alg = Algorithm::Single(<$params>::default().into());
                println!("Bench params: {:?}", alg);
                b.iter(|| {
                    alg.hash(password.clone().into())
                })
            }
        }

    }
}