1
+ #![ allow( non_upper_case_globals) ]
2
+
1
3
#[ macro_use]
2
4
extern crate criterion;
3
5
#[ macro_use]
4
6
extern crate lazy_static;
5
7
6
- use criterion:: { black_box, Bencher , BenchmarkId , Criterion , Throughput } ;
8
+ use criterion:: { black_box, Bencher , BenchmarkId , Criterion } ;
7
9
8
10
use bst_rs:: * ;
9
11
@@ -54,50 +56,17 @@ fn gen_u64s(size: usize) -> Vec<u64> {
54
56
( 0 ..size as u64 ) . into_iter ( ) . collect :: < Vec < _ > > ( )
55
57
}
56
58
57
- fn do_8bit_bench ( b : & mut Bencher , nums : & [ u8 ] ) {
58
- let mut r = 0usize ;
59
- b. iter ( || {
60
- r = r. wrapping_mul ( 1664525 ) . wrapping_add ( 1013904223 ) ;
61
- let i = r % nums. len ( ) ;
62
- black_box ( binary_search_auto ( & nums, i as u8 ) . is_some ( ) )
63
- } ) ;
64
- }
65
-
66
- fn do_16_bench ( b : & mut Bencher , nums : & [ u16 ] ) {
67
- let mut r = 0usize ;
68
- b. iter ( || {
69
- r = r. wrapping_mul ( 1664525 ) . wrapping_add ( 1013904223 ) ;
70
- let i = r % nums. len ( ) ;
71
- black_box ( binary_search_auto ( & nums, i as u16 ) . is_some ( ) )
72
- } ) ;
73
- }
74
-
75
- fn do_32_bench ( b : & mut Bencher , nums : & [ u32 ] ) {
76
- let mut r = 0usize ;
59
+ fn do_simd_bench < T : SIMDField > ( b : & mut Bencher , nums : & [ T ] ) {
60
+ let last = nums. last ( ) . unwrap ( ) ;
61
+ let last = * last;
77
62
b. iter ( || {
78
- r = r. wrapping_mul ( 1664525 ) . wrapping_add ( 1013904223 ) ;
79
- let i = r % nums. len ( ) ;
80
- black_box ( binary_search_auto ( & nums, i as u32 ) . is_some ( ) )
81
- } ) ;
82
- }
83
-
84
- fn do_64_bench ( b : & mut Bencher , nums : & [ u64 ] ) {
85
- let mut r = 0usize ;
86
- b. iter ( || {
87
- r = r. wrapping_mul ( 1664525 ) . wrapping_add ( 1013904223 ) ;
88
- let i = r % nums. len ( ) ;
89
- black_box ( binary_search_auto ( & nums, i as u64 ) . is_some ( ) )
63
+ black_box ( binary_search_auto ( & nums, last) . is_some ( ) ) ;
90
64
} ) ;
91
65
}
92
66
93
67
fn do_std_bench < T : num:: Integer + num:: FromPrimitive > ( b : & mut Bencher , nums : & [ T ] ) {
94
- let mut r = 0usize ;
95
- b. iter ( || {
96
- r = r. wrapping_mul ( 1664525 ) . wrapping_add ( 1013904223 ) ;
97
- let i = r % nums. len ( ) ;
98
- let i = T :: from_usize ( i) . unwrap ( ) ;
99
- black_box ( nums. binary_search ( & i) . is_ok ( ) )
100
- } ) ;
68
+ let last = nums. last ( ) . unwrap ( ) ;
69
+ b. iter ( || black_box ( nums. binary_search ( last) . is_ok ( ) ) ) ;
101
70
}
102
71
103
72
fn optimize_bst_bench ( c : & mut Criterion , label : & str ) {
@@ -108,110 +77,110 @@ fn optimize_bst_bench(c: &mut Criterion, label: &str) {
108
77
group. bench_with_input (
109
78
BenchmarkId :: new ( "optimize_on_8bit" , 4 ) ,
110
79
& * * U8x4 ,
111
- do_8bit_bench ,
80
+ do_simd_bench ,
112
81
) ;
113
82
group. bench_with_input (
114
83
BenchmarkId :: new ( "optimize_on_8bit" , 16 ) ,
115
- & U8x16 ,
116
- do_8bit_bench ,
84
+ & * * U8x16 ,
85
+ do_simd_bench ,
117
86
) ;
118
87
group. bench_with_input (
119
88
BenchmarkId :: new ( "optimize_on_8bit" , 128 ) ,
120
- & U8x128 ,
121
- do_8bit_bench ,
89
+ & * * U8x128 ,
90
+ do_simd_bench ,
122
91
) ;
123
92
//
124
93
group. bench_with_input (
125
94
BenchmarkId :: new ( "optimize_on_16bit" , 4 ) ,
126
- & U16x4 ,
127
- do_16_bench ,
95
+ & * * U16x4 ,
96
+ do_simd_bench ,
128
97
) ;
129
98
group. bench_with_input (
130
99
BenchmarkId :: new ( "optimize_on_16bit" , 16 ) ,
131
- & U16x16 ,
132
- do_16_bench ,
100
+ & * * U16x16 ,
101
+ do_simd_bench ,
133
102
) ;
134
103
group. bench_with_input (
135
104
BenchmarkId :: new ( "optimize_on_16bit" , 128 ) ,
136
- & U16x128 ,
137
- do_16_bench ,
105
+ & * * U16x128 ,
106
+ do_simd_bench ,
138
107
) ;
139
108
group. bench_with_input (
140
109
BenchmarkId :: new ( "optimize_on_16bit" , 512 ) ,
141
- & U16x512 ,
142
- do_16_bench ,
110
+ & * * U16x512 ,
111
+ do_simd_bench ,
143
112
) ;
144
113
group. bench_with_input (
145
114
BenchmarkId :: new ( "optimize_on_16bit" , 2048 ) ,
146
- & U16x2048 ,
147
- do_16_bench ,
115
+ & * * U16x2048 ,
116
+ do_simd_bench ,
148
117
) ;
149
118
group. bench_with_input (
150
119
BenchmarkId :: new ( "optimize_on_16bit" , 8192 ) ,
151
- & U16x8192 ,
152
- do_16_bench ,
120
+ & * * U16x8192 ,
121
+ do_simd_bench ,
153
122
) ;
154
123
//
155
124
group. bench_with_input (
156
125
BenchmarkId :: new ( "optimize_on_32bit" , 4 ) ,
157
- & U32x4 ,
158
- do_32_bench ,
126
+ & * * U32x4 ,
127
+ do_simd_bench ,
159
128
) ;
160
129
group. bench_with_input (
161
130
BenchmarkId :: new ( "optimize_on_32bit" , 16 ) ,
162
- & U32x16 ,
163
- do_32_bench ,
131
+ & * * U32x16 ,
132
+ do_simd_bench ,
164
133
) ;
165
134
group. bench_with_input (
166
135
BenchmarkId :: new ( "optimize_on_32bit" , 128 ) ,
167
- & U32x128 ,
168
- do_32_bench ,
136
+ & * * U32x128 ,
137
+ do_simd_bench ,
169
138
) ;
170
139
group. bench_with_input (
171
140
BenchmarkId :: new ( "optimize_on_32bit" , 512 ) ,
172
- & U32x512 ,
173
- do_32_bench ,
141
+ & * * U32x512 ,
142
+ do_simd_bench ,
174
143
) ;
175
144
group. bench_with_input (
176
145
BenchmarkId :: new ( "optimize_on_32bit" , 2048 ) ,
177
- & U32x2048 ,
178
- do_32_bench ,
146
+ & * * U32x2048 ,
147
+ do_simd_bench ,
179
148
) ;
180
149
group. bench_with_input (
181
150
BenchmarkId :: new ( "optimize_on_32bit" , 8192 ) ,
182
- & U32x8192 ,
183
- do_32_bench ,
151
+ & * * U32x8192 ,
152
+ do_simd_bench ,
184
153
) ;
185
154
//
186
155
group. bench_with_input (
187
156
BenchmarkId :: new ( "optimize_on_64bit" , 4 ) ,
188
- & U64x4 ,
189
- do_64_bench ,
157
+ & * * U64x4 ,
158
+ do_simd_bench ,
190
159
) ;
191
160
group. bench_with_input (
192
161
BenchmarkId :: new ( "optimize_on_64bit" , 16 ) ,
193
- & U64x16 ,
194
- do_64_bench ,
162
+ & * * U64x16 ,
163
+ do_simd_bench ,
195
164
) ;
196
165
group. bench_with_input (
197
166
BenchmarkId :: new ( "optimize_on_64bit" , 128 ) ,
198
- & U64x128 ,
199
- do_64_bench ,
167
+ & * * U64x128 ,
168
+ do_simd_bench ,
200
169
) ;
201
170
group. bench_with_input (
202
171
BenchmarkId :: new ( "optimize_on_64bit" , 512 ) ,
203
- & U64x512 ,
204
- do_64_bench ,
172
+ & * * U64x512 ,
173
+ do_simd_bench ,
205
174
) ;
206
175
group. bench_with_input (
207
176
BenchmarkId :: new ( "optimize_on_64bit" , 2048 ) ,
208
- & U64x2048 ,
209
- do_64_bench ,
177
+ & * * U64x2048 ,
178
+ do_simd_bench ,
210
179
) ;
211
180
group. bench_with_input (
212
181
BenchmarkId :: new ( "optimize_on_64bit" , 8192 ) ,
213
- & U64x8192 ,
214
- do_64_bench ,
182
+ & * * U64x8192 ,
183
+ do_simd_bench ,
215
184
) ;
216
185
group. finish ( ) ;
217
186
}
@@ -221,77 +190,93 @@ fn std_bst_bench(c: &mut Criterion, label: &str) {
221
190
group
222
191
. warm_up_time ( std:: time:: Duration :: from_millis ( 500 ) )
223
192
. measurement_time ( std:: time:: Duration :: from_secs ( 10 ) ) ;
224
- group. bench_with_input ( BenchmarkId :: new ( "std_on_8bit" , 4 ) , & U8x4 , do_std_bench) ;
225
- group. bench_with_input ( BenchmarkId :: new ( "std_on_8bit" , 16 ) , & U8x16 , do_std_bench) ;
226
- group. bench_with_input ( BenchmarkId :: new ( "std_on_8bit" , 128 ) , & U8x128 , do_std_bench) ;
193
+ group. bench_with_input ( BenchmarkId :: new ( "std_on_8bit" , 4 ) , & * * U8x4 , do_std_bench) ;
194
+ group. bench_with_input ( BenchmarkId :: new ( "std_on_8bit" , 16 ) , & * * U8x16 , do_std_bench) ;
195
+ group. bench_with_input (
196
+ BenchmarkId :: new ( "std_on_8bit" , 128 ) ,
197
+ & * * U8x128 ,
198
+ do_std_bench,
199
+ ) ;
227
200
//
228
201
//
229
- group. bench_with_input ( BenchmarkId :: new ( "std_on_16bit" , 4 ) , & U16x4 , do_std_bench) ;
230
- group. bench_with_input ( BenchmarkId :: new ( "std_on_16bit" , 16 ) , & U16x16 , do_std_bench) ;
202
+ group. bench_with_input ( BenchmarkId :: new ( "std_on_16bit" , 4 ) , & * * U16x4 , do_std_bench) ;
203
+ group. bench_with_input (
204
+ BenchmarkId :: new ( "std_on_16bit" , 16 ) ,
205
+ & * * U16x16 ,
206
+ do_std_bench,
207
+ ) ;
231
208
group. bench_with_input (
232
209
BenchmarkId :: new ( "std_on_16bit" , 128 ) ,
233
- & U16x128 ,
210
+ & * * U16x128 ,
234
211
do_std_bench,
235
212
) ;
236
213
group. bench_with_input (
237
214
BenchmarkId :: new ( "std_on_16bit" , 512 ) ,
238
- & U16x512 ,
215
+ & * * U16x512 ,
239
216
do_std_bench,
240
217
) ;
241
218
group. bench_with_input (
242
219
BenchmarkId :: new ( "std_on_16bit" , 2048 ) ,
243
- & U16x2048 ,
220
+ & * * U16x2048 ,
244
221
do_std_bench,
245
222
) ;
246
223
group. bench_with_input (
247
224
BenchmarkId :: new ( "std_on_16bit" , 8192 ) ,
248
- & U16x8192 ,
225
+ & * * U16x8192 ,
249
226
do_std_bench,
250
227
) ;
251
228
//
252
- group. bench_with_input ( BenchmarkId :: new ( "std_on_32bit" , 4 ) , & U32x4 , do_std_bench) ;
253
- group. bench_with_input ( BenchmarkId :: new ( "std_on_32bit" , 16 ) , & U32x16 , do_std_bench) ;
229
+ group. bench_with_input ( BenchmarkId :: new ( "std_on_32bit" , 4 ) , & * * U32x4 , do_std_bench) ;
230
+ group. bench_with_input (
231
+ BenchmarkId :: new ( "std_on_32bit" , 16 ) ,
232
+ & * * U32x16 ,
233
+ do_std_bench,
234
+ ) ;
254
235
group. bench_with_input (
255
236
BenchmarkId :: new ( "std_on_32bit" , 128 ) ,
256
- & U32x128 ,
237
+ & * * U32x128 ,
257
238
do_std_bench,
258
239
) ;
259
240
group. bench_with_input (
260
241
BenchmarkId :: new ( "std_on_32bit" , 512 ) ,
261
- & U32x512 ,
242
+ & * * U32x512 ,
262
243
do_std_bench,
263
244
) ;
264
245
group. bench_with_input (
265
246
BenchmarkId :: new ( "std_on_32bit" , 2048 ) ,
266
- & U32x2048 ,
247
+ & * * U32x2048 ,
267
248
do_std_bench,
268
249
) ;
269
250
group. bench_with_input (
270
251
BenchmarkId :: new ( "std_on_32bit" , 8192 ) ,
271
- & U32x8192 ,
252
+ & * * U32x8192 ,
272
253
do_std_bench,
273
254
) ;
274
255
//
275
- group. bench_with_input ( BenchmarkId :: new ( "std_on_64bit" , 4 ) , & U64x4 , do_std_bench) ;
276
- group. bench_with_input ( BenchmarkId :: new ( "std_on_64bit" , 16 ) , & U64x16 , do_std_bench) ;
256
+ group. bench_with_input ( BenchmarkId :: new ( "std_on_64bit" , 4 ) , & * * U64x4 , do_std_bench) ;
257
+ group. bench_with_input (
258
+ BenchmarkId :: new ( "std_on_64bit" , 16 ) ,
259
+ & * * U64x16 ,
260
+ do_std_bench,
261
+ ) ;
277
262
group. bench_with_input (
278
263
BenchmarkId :: new ( "std_on_64bit" , 128 ) ,
279
- & U64x128 ,
264
+ & * * U64x128 ,
280
265
do_std_bench,
281
266
) ;
282
267
group. bench_with_input (
283
268
BenchmarkId :: new ( "std_on_64bit" , 512 ) ,
284
- & U64x512 ,
269
+ & * * U64x512 ,
285
270
do_std_bench,
286
271
) ;
287
272
group. bench_with_input (
288
273
BenchmarkId :: new ( "std_on_64bit" , 2048 ) ,
289
- & U64x2048 ,
274
+ & * * U64x2048 ,
290
275
do_std_bench,
291
276
) ;
292
277
group. bench_with_input (
293
278
BenchmarkId :: new ( "std_on_64bit" , 8192 ) ,
294
- & U64x8192 ,
279
+ & * * U64x8192 ,
295
280
do_std_bench,
296
281
) ;
297
282
group. finish ( ) ;
0 commit comments