@@ -8,8 +8,8 @@ extern crate test;
8
8
9
9
use test:: { black_box, Bencher } ;
10
10
11
- use hashbrown:: HashMap ;
12
11
use hashbrown:: hash_map:: DefaultHashBuilder ;
12
+ use hashbrown:: HashMap ;
13
13
use std:: collections:: hash_map:: RandomState ;
14
14
15
15
const SIZE : usize = 1000 ;
@@ -28,15 +28,15 @@ struct RandomKeys {
28
28
29
29
impl RandomKeys {
30
30
fn new ( size : usize ) -> Self {
31
- RandomKeys {
31
+ RandomKeys {
32
32
remaining : size,
33
33
state : 1 ,
34
34
}
35
35
}
36
36
37
37
// Produce a different set of random values.
38
38
fn new2 ( size : usize ) -> Self {
39
- RandomKeys {
39
+ RandomKeys {
40
40
remaining : size,
41
41
state : 2 ,
42
42
}
@@ -70,13 +70,21 @@ macro_rules! bench_insert {
70
70
black_box( m) ;
71
71
} )
72
72
}
73
- }
73
+ } ;
74
74
}
75
75
76
76
bench_insert ! ( insert_fx_serial, FxHashMap , 0 ..SIZE ) ;
77
77
bench_insert ! ( insert_std_serial, StdHashMap , 0 ..SIZE ) ;
78
- bench_insert ! ( insert_fx_highbits, FxHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
79
- bench_insert ! ( insert_std_highbits, StdHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
78
+ bench_insert ! (
79
+ insert_fx_highbits,
80
+ FxHashMap ,
81
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
82
+ ) ;
83
+ bench_insert ! (
84
+ insert_std_highbits,
85
+ StdHashMap ,
86
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
87
+ ) ;
80
88
bench_insert ! ( insert_fx_random, FxHashMap , RandomKeys :: new( SIZE ) ) ;
81
89
bench_insert ! ( insert_std_random, StdHashMap , RandomKeys :: new( SIZE ) ) ;
82
90
@@ -96,13 +104,21 @@ macro_rules! bench_insert_erase {
96
104
black_box( m) ;
97
105
} )
98
106
}
99
- }
107
+ } ;
100
108
}
101
109
102
110
bench_insert_erase ! ( insert_erase_fx_serial, FxHashMap , 0 ..SIZE ) ;
103
111
bench_insert_erase ! ( insert_erase_std_serial, StdHashMap , 0 ..SIZE ) ;
104
- bench_insert_erase ! ( insert_erase_fx_highbits, FxHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
105
- bench_insert_erase ! ( insert_erase_std_highbits, StdHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
112
+ bench_insert_erase ! (
113
+ insert_erase_fx_highbits,
114
+ FxHashMap ,
115
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
116
+ ) ;
117
+ bench_insert_erase ! (
118
+ insert_erase_std_highbits,
119
+ StdHashMap ,
120
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
121
+ ) ;
106
122
bench_insert_erase ! ( insert_erase_fx_random, FxHashMap , RandomKeys :: new( SIZE ) ) ;
107
123
bench_insert_erase ! ( insert_erase_std_random, StdHashMap , RandomKeys :: new( SIZE ) ) ;
108
124
@@ -121,13 +137,21 @@ macro_rules! bench_lookup {
121
137
}
122
138
} )
123
139
}
124
- }
140
+ } ;
125
141
}
126
142
127
143
bench_lookup ! ( lookup_fx_serial, FxHashMap , 0 ..SIZE ) ;
128
144
bench_lookup ! ( lookup_std_serial, StdHashMap , 0 ..SIZE ) ;
129
- bench_lookup ! ( lookup_fx_highbits, FxHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
130
- bench_lookup ! ( lookup_std_highbits, StdHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
145
+ bench_lookup ! (
146
+ lookup_fx_highbits,
147
+ FxHashMap ,
148
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
149
+ ) ;
150
+ bench_lookup ! (
151
+ lookup_std_highbits,
152
+ StdHashMap ,
153
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
154
+ ) ;
131
155
bench_lookup ! ( lookup_fx_random, FxHashMap , RandomKeys :: new( SIZE ) ) ;
132
156
bench_lookup ! ( lookup_std_random, StdHashMap , RandomKeys :: new( SIZE ) ) ;
133
157
@@ -146,17 +170,35 @@ macro_rules! bench_lookup_fail {
146
170
}
147
171
} )
148
172
}
149
- }
173
+ } ;
150
174
}
151
175
152
- bench_lookup_fail ! ( lookup_fail_fx_serial, FxHashMap , 0 ..SIZE , SIZE ..SIZE * 2 ) ;
153
- bench_lookup_fail ! ( lookup_fail_std_serial, StdHashMap , 0 ..SIZE , SIZE ..SIZE * 2 ) ;
154
- bench_lookup_fail ! ( lookup_fail_fx_highbits, FxHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ,
155
- ( SIZE ..SIZE * 2 ) . map( usize :: swap_bytes) ) ;
156
- bench_lookup_fail ! ( lookup_fail_std_highbits, StdHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ,
157
- ( SIZE ..SIZE * 2 ) . map( usize :: swap_bytes) ) ;
158
- bench_lookup_fail ! ( lookup_fail_fx_random, FxHashMap , RandomKeys :: new( SIZE ) , RandomKeys :: new2( SIZE ) ) ;
159
- bench_lookup_fail ! ( lookup_fail_std_random, StdHashMap , RandomKeys :: new( SIZE ) , RandomKeys :: new2( SIZE ) ) ;
176
+ bench_lookup_fail ! ( lookup_fail_fx_serial, FxHashMap , 0 ..SIZE , SIZE ..SIZE * 2 ) ;
177
+ bench_lookup_fail ! ( lookup_fail_std_serial, StdHashMap , 0 ..SIZE , SIZE ..SIZE * 2 ) ;
178
+ bench_lookup_fail ! (
179
+ lookup_fail_fx_highbits,
180
+ FxHashMap ,
181
+ ( 0 ..SIZE ) . map( usize :: swap_bytes) ,
182
+ ( SIZE ..SIZE * 2 ) . map( usize :: swap_bytes)
183
+ ) ;
184
+ bench_lookup_fail ! (
185
+ lookup_fail_std_highbits,
186
+ StdHashMap ,
187
+ ( 0 ..SIZE ) . map( usize :: swap_bytes) ,
188
+ ( SIZE ..SIZE * 2 ) . map( usize :: swap_bytes)
189
+ ) ;
190
+ bench_lookup_fail ! (
191
+ lookup_fail_fx_random,
192
+ FxHashMap ,
193
+ RandomKeys :: new( SIZE ) ,
194
+ RandomKeys :: new2( SIZE )
195
+ ) ;
196
+ bench_lookup_fail ! (
197
+ lookup_fail_std_random,
198
+ StdHashMap ,
199
+ RandomKeys :: new( SIZE ) ,
200
+ RandomKeys :: new2( SIZE )
201
+ ) ;
160
202
161
203
macro_rules! bench_iter {
162
204
( $name: ident, $maptype: ident, $keydist: expr) => {
@@ -173,12 +215,20 @@ macro_rules! bench_iter {
173
215
}
174
216
} )
175
217
}
176
- }
218
+ } ;
177
219
}
178
220
179
221
bench_iter ! ( iter_fx_serial, FxHashMap , 0 ..SIZE ) ;
180
222
bench_iter ! ( iter_std_serial, StdHashMap , 0 ..SIZE ) ;
181
- bench_iter ! ( iter_fx_highbits, FxHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
182
- bench_iter ! ( iter_std_highbits, StdHashMap , ( 0 ..SIZE ) . map( usize :: swap_bytes) ) ;
223
+ bench_iter ! (
224
+ iter_fx_highbits,
225
+ FxHashMap ,
226
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
227
+ ) ;
228
+ bench_iter ! (
229
+ iter_std_highbits,
230
+ StdHashMap ,
231
+ ( 0 ..SIZE ) . map( usize :: swap_bytes)
232
+ ) ;
183
233
bench_iter ! ( iter_fx_random, FxHashMap , RandomKeys :: new( SIZE ) ) ;
184
234
bench_iter ! ( iter_std_random, StdHashMap , RandomKeys :: new( SIZE ) ) ;
0 commit comments