1
+ use std:: collections:: HashSet ;
2
+
1
3
use argon2:: * ;
2
4
use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
3
5
use pprof:: criterion:: { Output , PProfProfiler } ;
@@ -26,46 +28,26 @@ fn bench_default_params(c: &mut Criterion) {
26
28
}
27
29
}
28
30
29
- fn bench_vary_m ( c : & mut Criterion ) {
30
- let t_cost = 4 ;
31
- let p_cost = 4 ;
32
- for m_cost in [ 2 * 1024 , 16 * 1024 , 64 * 1024 , 256 * 1024 ] {
33
- let test_name = format ! ( "argon2id V0x13 m={m_cost} t={t_cost} p={p_cost}" ) ;
34
- c. bench_function ( & test_name, |b| {
35
- let mut out = [ 0u8 ; 32 ] ;
36
- let params = Params :: new ( m_cost, t_cost, p_cost, Some ( 32 ) ) . unwrap ( ) ;
37
- let argon2 = Argon2 :: new ( Algorithm :: Argon2id , Version :: V0x13 , params) ;
38
- b. iter ( || {
39
- argon2
40
- . hash_password_into ( black_box ( BENCH_PASSWORD ) , black_box ( BENCH_SALT ) , & mut out)
41
- . unwrap ( )
42
- } )
43
- } ) ;
31
+ fn bench_vary_params ( c : & mut Criterion ) {
32
+ let mut tests = HashSet :: new ( ) ;
33
+ // Vary `m_cost`.
34
+ for m_cost in [ 2 * 1024 , 16 * 1024 , 32 * 1024 , 64 * 1024 , 256 * 1024 ] {
35
+ tests. insert ( ( m_cost, 4 , 4 ) ) ;
44
36
}
45
- }
46
-
47
- fn bench_vary_t ( c : & mut Criterion ) {
48
- let m_cost = 32 * 1024 ;
49
- let p_cost = 4 ;
50
- for t_cost in [ 2 , 8 , 16 , 24 ] {
51
- let test_name = format ! ( "argon2id V0x13 m={m_cost} t={t_cost} p={p_cost}" ) ;
52
- c. bench_function ( & test_name, |b| {
53
- let mut out = [ 0u8 ; 32 ] ;
54
- let params = Params :: new ( m_cost, t_cost, p_cost, Some ( 32 ) ) . unwrap ( ) ;
55
- let argon2 = Argon2 :: new ( Algorithm :: Argon2id , Version :: V0x13 , params) ;
56
- b. iter ( || {
57
- argon2
58
- . hash_password_into ( black_box ( BENCH_PASSWORD ) , black_box ( BENCH_SALT ) , & mut out)
59
- . unwrap ( )
60
- } )
61
- } ) ;
37
+ // Vary `t_cost`.
38
+ for t_cost in [ 1 , 2 , 4 , 8 , 16 ] {
39
+ tests. insert ( ( 32 * 1024 , t_cost, 4 ) ) ;
62
40
}
63
- }
64
-
65
- fn bench_vary_p ( c : & mut Criterion ) {
66
- let m_cost = 32 * 1024 ;
67
- let t_cost = 4 ;
68
- for p_cost in [ 2 , 8 , 16 , 64 ] {
41
+ // Vary `p_cost`.
42
+ for p_cost in [ 1 , 2 , 4 , 8 , 16 ] {
43
+ for m_mib in [ 256 * 1024 , 1024 * 1024 ] {
44
+ tests. insert ( ( m_mib, 1 , p_cost) ) ;
45
+ }
46
+ for t_cost in [ 1 , 2 , 4 ] {
47
+ tests. insert ( ( 32 * 1024 , t_cost, p_cost) ) ;
48
+ }
49
+ }
50
+ for ( m_cost, t_cost, p_cost) in tests {
69
51
let test_name = format ! ( "argon2id V0x13 m={m_cost} t={t_cost} p={p_cost}" ) ;
70
52
c. bench_function ( & test_name, |b| {
71
53
let mut out = [ 0u8 ; 32 ] ;
@@ -85,8 +67,6 @@ criterion_group!(
85
67
config = Criterion :: default ( ) . with_profiler( PProfProfiler :: new( 300 , Output :: Flamegraph ( None ) ) ) ;
86
68
targets =
87
69
bench_default_params,
88
- bench_vary_m,
89
- bench_vary_t,
90
- bench_vary_p,
70
+ bench_vary_params,
91
71
) ;
92
72
criterion_main ! ( benches) ;
0 commit comments