@@ -19,7 +19,7 @@ use std::cell::RefCell;
19
19
pub struct Unit ;
20
20
21
21
pub struct BencherConfig < GenI = Unit > {
22
- gen_input : GenI ,
22
+ gen_input : RefCell < GenI > ,
23
23
}
24
24
25
25
pub struct Bencher < ' a , ' b , C = BencherConfig > {
@@ -29,11 +29,12 @@ pub struct Bencher<'a, 'b, C = BencherConfig> {
29
29
pub ( crate ) _marker : std:: marker:: PhantomData < & ' b ( ) > ,
30
30
}
31
31
32
- #[ allow( clippy:: needless_lifetimes) ]
33
32
impl < ' a , ' b > Bencher < ' a , ' b > {
34
33
pub ( crate ) fn new ( codspeed : & ' a RefCell < CodSpeed > , uri : String ) -> Self {
35
34
Self {
36
- config : BencherConfig { gen_input : Unit } ,
35
+ config : BencherConfig {
36
+ gen_input : RefCell :: new ( Unit ) ,
37
+ } ,
37
38
codspeed,
38
39
uri,
39
40
_marker : std:: marker:: PhantomData ,
@@ -42,7 +43,9 @@ impl<'a, 'b> Bencher<'a, 'b> {
42
43
43
44
pub fn with_inputs < G > ( self , gen_input : G ) -> Bencher < ' a , ' b , BencherConfig < G > > {
44
45
Bencher {
45
- config : BencherConfig { gen_input } ,
46
+ config : BencherConfig {
47
+ gen_input : RefCell :: new ( gen_input) ,
48
+ } ,
46
49
codspeed : self . codspeed ,
47
50
uri : self . uri ,
48
51
_marker : self . _marker ,
@@ -58,9 +61,9 @@ impl<'a, 'b> Bencher<'a, 'b> {
58
61
self . with_inputs ( || ( ) ) . bench_values ( |_| benched ( ) )
59
62
}
60
63
61
- pub fn bench_local < O , B > ( self , benched : B )
64
+ pub fn bench_local < O , B > ( self , mut benched : B )
62
65
where
63
- B : Fn ( ) -> O ,
66
+ B : FnMut ( ) -> O ,
64
67
{
65
68
self . with_inputs ( || ( ) ) . bench_local_values ( |_| benched ( ) )
66
69
}
@@ -86,24 +89,24 @@ where
86
89
self . bench_local_refs ( benched)
87
90
}
88
91
89
- pub fn bench_local_values < O , B > ( mut self , benched : B )
92
+ pub fn bench_local_values < O , B > ( self , mut benched : B )
90
93
where
91
- B : Fn ( I ) -> O ,
94
+ B : FnMut ( I ) -> O ,
92
95
{
93
96
let mut codspeed = self . codspeed . borrow_mut ( ) ;
94
- let gen_input = & mut self . config . gen_input ;
97
+ let mut gen_input = self . config . gen_input . borrow_mut ( ) ;
95
98
let input = gen_input ( ) ;
96
99
codspeed. start_benchmark ( self . uri . as_str ( ) ) ;
97
100
divan:: black_box ( benched ( input) ) ;
98
101
codspeed. end_benchmark ( ) ;
99
102
}
100
103
101
- pub fn bench_local_refs < O , B > ( mut self , mut benched : B )
104
+ pub fn bench_local_refs < O , B > ( self , mut benched : B )
102
105
where
103
106
B : FnMut ( & mut I ) -> O ,
104
107
{
105
108
let mut codspeed = self . codspeed . borrow_mut ( ) ;
106
- let gen_input = & mut self . config . gen_input ;
109
+ let mut gen_input = self . config . gen_input . borrow_mut ( ) ;
107
110
let mut input = gen_input ( ) ;
108
111
109
112
codspeed. start_benchmark ( self . uri . as_str ( ) ) ;
0 commit comments