1
1
#![ feature( test) ]
2
- extern crate test;
3
- extern crate rand;
4
2
extern crate fnv;
3
+ extern crate rand;
4
+ extern crate test;
5
5
#[ macro_use]
6
6
extern crate lazy_static;
7
7
8
- use std:: hash:: Hash ;
9
8
use fnv:: FnvHasher ;
10
9
use std:: hash:: BuildHasherDefault ;
10
+ use std:: hash:: Hash ;
11
11
type FnvBuilder = BuildHasherDefault < FnvHasher > ;
12
12
13
- use test:: Bencher ;
14
13
use test:: black_box;
14
+ use test:: Bencher ;
15
15
16
16
extern crate indexmap;
17
17
@@ -21,35 +21,27 @@ use std::collections::HashMap;
21
21
use std:: iter:: FromIterator ;
22
22
23
23
use rand:: rngs:: SmallRng ;
24
- use rand:: FromEntropy ;
25
24
use rand:: seq:: SliceRandom ;
25
+ use rand:: FromEntropy ;
26
26
27
27
#[ bench]
28
28
fn new_hashmap ( b : & mut Bencher ) {
29
- b. iter ( || {
30
- HashMap :: < String , String > :: new ( )
31
- } ) ;
29
+ b. iter ( || HashMap :: < String , String > :: new ( ) ) ;
32
30
}
33
31
34
32
#[ bench]
35
33
fn new_orderedmap ( b : & mut Bencher ) {
36
- b. iter ( || {
37
- IndexMap :: < String , String > :: new ( )
38
- } ) ;
34
+ b. iter ( || IndexMap :: < String , String > :: new ( ) ) ;
39
35
}
40
36
41
37
#[ bench]
42
38
fn with_capacity_10e5_hashmap ( b : & mut Bencher ) {
43
- b. iter ( || {
44
- HashMap :: < String , String > :: with_capacity ( 10_000 )
45
- } ) ;
39
+ b. iter ( || HashMap :: < String , String > :: with_capacity ( 10_000 ) ) ;
46
40
}
47
41
48
42
#[ bench]
49
43
fn with_capacity_10e5_orderedmap ( b : & mut Bencher ) {
50
- b. iter ( || {
51
- IndexMap :: < String , String > :: with_capacity ( 10_000 )
52
- } ) ;
44
+ b. iter ( || IndexMap :: < String , String > :: with_capacity ( 10_000 ) ) ;
53
45
}
54
46
55
47
#[ bench]
@@ -228,35 +220,31 @@ fn entry_orderedmap_150(b: &mut Bencher) {
228
220
fn iter_sum_hashmap_10_000 ( b : & mut Bencher ) {
229
221
let c = 10_000 ;
230
222
let mut map = HashMap :: with_capacity ( c) ;
231
- let len = c - c/ 10 ;
223
+ let len = c - c / 10 ;
232
224
for x in 0 ..len {
233
225
map. insert ( x, ( ) ) ;
234
226
}
235
227
assert_eq ! ( map. len( ) , len) ;
236
- b. iter ( || {
237
- map. keys ( ) . sum :: < usize > ( )
238
- } ) ;
228
+ b. iter ( || map. keys ( ) . sum :: < usize > ( ) ) ;
239
229
}
240
230
241
231
#[ bench]
242
232
fn iter_sum_orderedmap_10_000 ( b : & mut Bencher ) {
243
233
let c = 10_000 ;
244
234
let mut map = IndexMap :: with_capacity ( c) ;
245
- let len = c - c/ 10 ;
235
+ let len = c - c / 10 ;
246
236
for x in 0 ..len {
247
237
map. insert ( x, ( ) ) ;
248
238
}
249
239
assert_eq ! ( map. len( ) , len) ;
250
- b. iter ( || {
251
- map. keys ( ) . sum :: < usize > ( )
252
- } ) ;
240
+ b. iter ( || map. keys ( ) . sum :: < usize > ( ) ) ;
253
241
}
254
242
255
243
#[ bench]
256
244
fn iter_black_box_hashmap_10_000 ( b : & mut Bencher ) {
257
245
let c = 10_000 ;
258
246
let mut map = HashMap :: with_capacity ( c) ;
259
- let len = c - c/ 10 ;
247
+ let len = c - c / 10 ;
260
248
for x in 0 ..len {
261
249
map. insert ( x, ( ) ) ;
262
250
}
@@ -272,7 +260,7 @@ fn iter_black_box_hashmap_10_000(b: &mut Bencher) {
272
260
fn iter_black_box_orderedmap_10_000 ( b : & mut Bencher ) {
273
261
let c = 10_000 ;
274
262
let mut map = IndexMap :: with_capacity ( c) ;
275
- let len = c - c/ 10 ;
263
+ let len = c - c / 10 ;
276
264
for x in 0 ..len {
277
265
map. insert ( x, ( ) ) ;
278
266
}
@@ -285,7 +273,8 @@ fn iter_black_box_orderedmap_10_000(b: &mut Bencher) {
285
273
}
286
274
287
275
fn shuffled_keys < I > ( iter : I ) -> Vec < I :: Item >
288
- where I : IntoIterator
276
+ where
277
+ I : IntoIterator ,
289
278
{
290
279
let mut v = Vec :: from_iter ( iter) ;
291
280
let mut rng = SmallRng :: from_entropy ( ) ;
@@ -366,12 +355,9 @@ const LOOKUP_MAP_SIZE: u32 = 100_000_u32;
366
355
const LOOKUP_SAMPLE_SIZE : u32 = 5000 ;
367
356
const SORT_MAP_SIZE : usize = 10_000 ;
368
357
369
-
370
358
// use lazy_static so that comparison benchmarks use the exact same inputs
371
359
lazy_static ! {
372
- static ref KEYS : Vec <u32 > = {
373
- shuffled_keys( 0 ..LOOKUP_MAP_SIZE )
374
- } ;
360
+ static ref KEYS : Vec <u32 > = { shuffled_keys( 0 ..LOOKUP_MAP_SIZE ) } ;
375
361
}
376
362
377
363
lazy_static ! {
@@ -429,7 +415,6 @@ fn lookup_hashmap_100_000_multi(b: &mut Bencher) {
429
415
} ) ;
430
416
}
431
417
432
-
433
418
#[ bench]
434
419
fn lookup_ordermap_100_000_multi ( b : & mut Bencher ) {
435
420
let map = & * OMAP_100K ;
@@ -456,7 +441,6 @@ fn lookup_hashmap_100_000_inorder_multi(b: &mut Bencher) {
456
441
} ) ;
457
442
}
458
443
459
-
460
444
#[ bench]
461
445
fn lookup_ordermap_100_000_inorder_multi ( b : & mut Bencher ) {
462
446
let map = & * OMAP_100K ;
@@ -480,7 +464,6 @@ fn lookup_hashmap_100_000_single(b: &mut Bencher) {
480
464
} ) ;
481
465
}
482
466
483
-
484
467
#[ bench]
485
468
fn lookup_ordermap_100_000_single ( b : & mut Bencher ) {
486
469
let map = & * OMAP_100K ;
@@ -517,7 +500,6 @@ fn grow_fnv_ordermap_100_000(b: &mut Bencher) {
517
500
} ) ;
518
501
}
519
502
520
-
521
503
const MERGE : u64 = 10_000 ;
522
504
#[ bench]
523
505
fn hashmap_merge_simple ( b : & mut Bencher ) {
@@ -708,15 +690,13 @@ fn many_retain_hashmap_100_000(b: &mut Bencher) {
708
690
} ) ;
709
691
}
710
692
711
-
712
693
// simple sort impl for comparison
713
694
pub fn simple_sort < K : Ord + Hash , V > ( m : & mut IndexMap < K , V > ) {
714
695
let mut ordered: Vec < _ > = m. drain ( ..) . collect ( ) ;
715
696
ordered. sort_by ( |left, right| left. 0 . cmp ( & right. 0 ) ) ;
716
697
m. extend ( ordered) ;
717
698
}
718
699
719
-
720
700
#[ bench]
721
701
fn ordermap_sort_s ( b : & mut Bencher ) {
722
702
let map = OMAP_SORT_S . clone ( ) ;
@@ -770,17 +750,12 @@ fn ordermap_simple_sort_u32(b: &mut Bencher) {
770
750
fn ordermap_clone_for_sort_s ( b : & mut Bencher ) {
771
751
let map = OMAP_SORT_S . clone ( ) ;
772
752
773
- b. iter ( || {
774
- map. clone ( )
775
- } ) ;
753
+ b. iter ( || map. clone ( ) ) ;
776
754
}
777
755
778
756
#[ bench]
779
757
fn ordermap_clone_for_sort_u32 ( b : & mut Bencher ) {
780
758
let map = OMAP_SORT_U32 . clone ( ) ;
781
759
782
- b. iter ( || {
783
- map. clone ( )
784
- } ) ;
760
+ b. iter ( || map. clone ( ) ) ;
785
761
}
786
-
0 commit comments