@@ -5,11 +5,13 @@ extern crate rand;
5
5
extern crate test;
6
6
7
7
macro_rules! bench_num {
8
- ( $name: ident, $read: ident, $bytes: expr, $data: expr) => (
8
+ ( $name: ident, $read: ident, $bytes: expr, $data: expr) => {
9
9
mod $name {
10
- use byteorder:: { ByteOrder , BigEndian , NativeEndian , LittleEndian } ;
11
- use super :: test:: Bencher ;
12
10
use super :: test:: black_box as bb;
11
+ use super :: test:: Bencher ;
12
+ use byteorder:: {
13
+ BigEndian , ByteOrder , LittleEndian , NativeEndian ,
14
+ } ;
13
15
14
16
const NITER : usize = 100_000 ;
15
17
@@ -43,14 +45,16 @@ macro_rules! bench_num {
43
45
} ) ;
44
46
}
45
47
}
46
- ) ;
48
+ } ;
47
49
( $ty: ident, $max: ident,
48
- $read: ident, $write: ident, $size: expr, $data: expr) => (
50
+ $read: ident, $write: ident, $size: expr, $data: expr) => {
49
51
mod $ty {
50
- use std:: $ty;
51
- use byteorder:: { ByteOrder , BigEndian , NativeEndian , LittleEndian } ;
52
- use super :: test:: Bencher ;
53
52
use super :: test:: black_box as bb;
53
+ use super :: test:: Bencher ;
54
+ use byteorder:: {
55
+ BigEndian , ByteOrder , LittleEndian , NativeEndian ,
56
+ } ;
57
+ use std:: $ty;
54
58
55
59
const NITER : usize = 100_000 ;
56
60
@@ -117,7 +121,7 @@ macro_rules! bench_num {
117
121
} ) ;
118
122
}
119
123
}
120
- ) ;
124
+ } ;
121
125
}
122
126
123
127
bench_num ! ( u16 , MAX , read_u16, write_u16, 2 , [ 1 , 2 ] ) ;
@@ -127,8 +131,7 @@ bench_num!(i32, MAX, read_i32, write_i32, 4, [1, 2, 3, 4]);
127
131
bench_num ! ( u64 , MAX , read_u64, write_u64, 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
128
132
bench_num ! ( i64 , MAX , read_i64, write_i64, 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
129
133
bench_num ! ( f32 , MAX , read_f32, write_f32, 4 , [ 1 , 2 , 3 , 4 ] ) ;
130
- bench_num ! ( f64 , MAX , read_f64, write_f64, 8 ,
131
- [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
134
+ bench_num ! ( f64 , MAX , read_f64, write_f64, 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
132
135
133
136
bench_num ! ( uint_1, read_uint, 1 , [ 1 ] ) ;
134
137
bench_num ! ( uint_2, read_uint, 2 , [ 1 , 2 ] ) ;
@@ -149,119 +152,148 @@ bench_num!(int_7, read_int, 7, [1, 2, 3, 4, 5, 6, 7]);
149
152
bench_num ! ( int_8, read_int, 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
150
153
151
154
#[ cfg( byteorder_i128) ]
152
- bench_num ! ( u128 , MAX , read_u128, write_u128,
153
- 16 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ) ;
154
- #[ cfg( byteorder_i128) ]
155
- bench_num ! ( i128 , MAX , read_i128, write_i128,
156
- 16 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ) ;
155
+ bench_num ! (
156
+ u128 ,
157
+ MAX ,
158
+ read_u128,
159
+ write_u128,
160
+ 16 ,
161
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ]
162
+ ) ;
163
+ #[ cfg( byteorder_i128) ]
164
+ bench_num ! (
165
+ i128 ,
166
+ MAX ,
167
+ read_i128,
168
+ write_i128,
169
+ 16 ,
170
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ]
171
+ ) ;
157
172
158
173
#[ cfg( byteorder_i128) ]
159
- bench_num ! ( uint128_1, read_uint128,
160
- 1 , [ 1 ] ) ;
174
+ bench_num ! ( uint128_1, read_uint128, 1 , [ 1 ] ) ;
161
175
#[ cfg( byteorder_i128) ]
162
- bench_num ! ( uint128_2, read_uint128,
163
- 2 , [ 1 , 2 ] ) ;
176
+ bench_num ! ( uint128_2, read_uint128, 2 , [ 1 , 2 ] ) ;
164
177
#[ cfg( byteorder_i128) ]
165
- bench_num ! ( uint128_3, read_uint128,
166
- 3 , [ 1 , 2 , 3 ] ) ;
178
+ bench_num ! ( uint128_3, read_uint128, 3 , [ 1 , 2 , 3 ] ) ;
167
179
#[ cfg( byteorder_i128) ]
168
- bench_num ! ( uint128_4, read_uint128,
169
- 4 , [ 1 , 2 , 3 , 4 ] ) ;
180
+ bench_num ! ( uint128_4, read_uint128, 4 , [ 1 , 2 , 3 , 4 ] ) ;
170
181
#[ cfg( byteorder_i128) ]
171
- bench_num ! ( uint128_5, read_uint128,
172
- 5 , [ 1 , 2 , 3 , 4 , 5 ] ) ;
182
+ bench_num ! ( uint128_5, read_uint128, 5 , [ 1 , 2 , 3 , 4 , 5 ] ) ;
173
183
#[ cfg( byteorder_i128) ]
174
- bench_num ! ( uint128_6, read_uint128,
175
- 6 , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
184
+ bench_num ! ( uint128_6, read_uint128, 6 , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
176
185
#[ cfg( byteorder_i128) ]
177
- bench_num ! ( uint128_7, read_uint128,
178
- 7 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
186
+ bench_num ! ( uint128_7, read_uint128, 7 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
179
187
#[ cfg( byteorder_i128) ]
180
- bench_num ! ( uint128_8, read_uint128,
181
- 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
188
+ bench_num ! ( uint128_8, read_uint128, 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
182
189
#[ cfg( byteorder_i128) ]
183
- bench_num ! ( uint128_9, read_uint128,
184
- 9 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ;
190
+ bench_num ! ( uint128_9, read_uint128, 9 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ;
185
191
#[ cfg( byteorder_i128) ]
186
- bench_num ! ( uint128_10, read_uint128,
187
- 10 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
192
+ bench_num ! ( uint128_10, read_uint128, 10 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
188
193
#[ cfg( byteorder_i128) ]
189
- bench_num ! ( uint128_11, read_uint128,
190
- 11 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ;
194
+ bench_num ! ( uint128_11, read_uint128, 11 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ;
191
195
#[ cfg( byteorder_i128) ]
192
- bench_num ! ( uint128_12, read_uint128,
193
- 12 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ) ;
196
+ bench_num ! (
197
+ uint128_12,
198
+ read_uint128,
199
+ 12 ,
200
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ]
201
+ ) ;
194
202
#[ cfg( byteorder_i128) ]
195
- bench_num ! ( uint128_13, read_uint128,
196
- 13 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] ) ;
203
+ bench_num ! (
204
+ uint128_13,
205
+ read_uint128,
206
+ 13 ,
207
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ]
208
+ ) ;
197
209
#[ cfg( byteorder_i128) ]
198
- bench_num ! ( uint128_14, read_uint128,
199
- 14 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ] ) ;
210
+ bench_num ! (
211
+ uint128_14,
212
+ read_uint128,
213
+ 14 ,
214
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ]
215
+ ) ;
200
216
#[ cfg( byteorder_i128) ]
201
- bench_num ! ( uint128_15, read_uint128,
202
- 15 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] ) ;
217
+ bench_num ! (
218
+ uint128_15,
219
+ read_uint128,
220
+ 15 ,
221
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ]
222
+ ) ;
203
223
#[ cfg( byteorder_i128) ]
204
- bench_num ! ( uint128_16, read_uint128,
205
- 16 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ) ;
224
+ bench_num ! (
225
+ uint128_16,
226
+ read_uint128,
227
+ 16 ,
228
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ]
229
+ ) ;
206
230
207
231
#[ cfg( byteorder_i128) ]
208
- bench_num ! ( int128_1, read_int128,
209
- 1 , [ 1 ] ) ;
232
+ bench_num ! ( int128_1, read_int128, 1 , [ 1 ] ) ;
210
233
#[ cfg( byteorder_i128) ]
211
- bench_num ! ( int128_2, read_int128,
212
- 2 , [ 1 , 2 ] ) ;
234
+ bench_num ! ( int128_2, read_int128, 2 , [ 1 , 2 ] ) ;
213
235
#[ cfg( byteorder_i128) ]
214
- bench_num ! ( int128_3, read_int128,
215
- 3 , [ 1 , 2 , 3 ] ) ;
236
+ bench_num ! ( int128_3, read_int128, 3 , [ 1 , 2 , 3 ] ) ;
216
237
#[ cfg( byteorder_i128) ]
217
- bench_num ! ( int128_4, read_int128,
218
- 4 , [ 1 , 2 , 3 , 4 ] ) ;
238
+ bench_num ! ( int128_4, read_int128, 4 , [ 1 , 2 , 3 , 4 ] ) ;
219
239
#[ cfg( byteorder_i128) ]
220
- bench_num ! ( int128_5, read_int128,
221
- 5 , [ 1 , 2 , 3 , 4 , 5 ] ) ;
240
+ bench_num ! ( int128_5, read_int128, 5 , [ 1 , 2 , 3 , 4 , 5 ] ) ;
222
241
#[ cfg( byteorder_i128) ]
223
- bench_num ! ( int128_6, read_int128,
224
- 6 , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
242
+ bench_num ! ( int128_6, read_int128, 6 , [ 1 , 2 , 3 , 4 , 5 , 6 ] ) ;
225
243
#[ cfg( byteorder_i128) ]
226
- bench_num ! ( int128_7, read_int128,
227
- 7 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
244
+ bench_num ! ( int128_7, read_int128, 7 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] ) ;
228
245
#[ cfg( byteorder_i128) ]
229
- bench_num ! ( int128_8, read_int128,
230
- 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
246
+ bench_num ! ( int128_8, read_int128, 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
231
247
#[ cfg( byteorder_i128) ]
232
- bench_num ! ( int128_9, read_int128,
233
- 9 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ;
248
+ bench_num ! ( int128_9, read_int128, 9 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] ) ;
234
249
#[ cfg( byteorder_i128) ]
235
- bench_num ! ( int128_10, read_int128,
236
- 10 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
250
+ bench_num ! ( int128_10, read_int128, 10 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ) ;
237
251
#[ cfg( byteorder_i128) ]
238
- bench_num ! ( int128_11, read_int128,
239
- 11 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ;
252
+ bench_num ! ( int128_11, read_int128, 11 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ] ) ;
240
253
#[ cfg( byteorder_i128) ]
241
- bench_num ! ( int128_12, read_int128,
242
- 12 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ) ;
254
+ bench_num ! (
255
+ int128_12,
256
+ read_int128,
257
+ 12 ,
258
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ]
259
+ ) ;
243
260
#[ cfg( byteorder_i128) ]
244
- bench_num ! ( int128_13, read_int128,
245
- 13 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ] ) ;
261
+ bench_num ! (
262
+ int128_13,
263
+ read_int128,
264
+ 13 ,
265
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 ]
266
+ ) ;
246
267
#[ cfg( byteorder_i128) ]
247
- bench_num ! ( int128_14, read_int128,
248
- 14 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ] ) ;
268
+ bench_num ! (
269
+ int128_14,
270
+ read_int128,
271
+ 14 ,
272
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ]
273
+ ) ;
249
274
#[ cfg( byteorder_i128) ]
250
- bench_num ! ( int128_15, read_int128,
251
- 15 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ] ) ;
275
+ bench_num ! (
276
+ int128_15,
277
+ read_int128,
278
+ 15 ,
279
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 ]
280
+ ) ;
252
281
#[ cfg( byteorder_i128) ]
253
- bench_num ! ( int128_16, read_int128,
254
- 16 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ] ) ;
255
-
282
+ bench_num ! (
283
+ int128_16,
284
+ read_int128,
285
+ 16 ,
286
+ [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 , 15 , 16 ]
287
+ ) ;
256
288
257
289
macro_rules! bench_slice {
258
290
( $name: ident, $numty: ty, $read: ident, $write: ident) => {
259
291
mod $name {
260
292
use std:: mem:: size_of;
261
293
262
- use byteorder:: { ByteOrder , BigEndian , LittleEndian } ;
263
- use rand:: { self , Rng } ;
294
+ use byteorder:: { BigEndian , ByteOrder , LittleEndian } ;
264
295
use rand:: distributions;
296
+ use rand:: { self , Rng } ;
265
297
use test:: Bencher ;
266
298
267
299
#[ bench]
@@ -322,7 +354,7 @@ macro_rules! bench_slice {
322
354
} ) ;
323
355
}
324
356
}
325
- }
357
+ } ;
326
358
}
327
359
328
360
bench_slice ! ( slice_u64, u64 , read_u64_into, write_u64_into) ;
0 commit comments