@@ -5,6 +5,7 @@ extern crate fnv;
5
5
#[ macro_use]
6
6
extern crate lazy_static;
7
7
8
+ use std:: hash:: Hash ;
8
9
use fnv:: FnvHasher ;
9
10
use std:: hash:: BuildHasherDefault ;
10
11
type FnvBuilder = BuildHasherDefault < FnvHasher > ;
@@ -361,13 +362,16 @@ fn lookup_orderedmap_10_000_noexist(b: &mut Bencher) {
361
362
// number of items to look up
362
363
const LOOKUP_MAP_SIZE : u32 = 100_000_u32 ;
363
364
const LOOKUP_SAMPLE_SIZE : u32 = 5000 ;
365
+ const SORT_MAP_SIZE : usize = 10_000 ;
364
366
365
367
368
+ // use lazy_static so that comparison benchmarks use the exact same inputs
366
369
lazy_static ! {
367
370
static ref KEYS : Vec <u32 > = {
368
371
shuffled_keys( 0 ..LOOKUP_MAP_SIZE )
369
372
} ;
370
373
}
374
+
371
375
lazy_static ! {
372
376
static ref HMAP_100K : HashMap <u32 , u32 > = {
373
377
let c = LOOKUP_MAP_SIZE ;
@@ -392,6 +396,25 @@ lazy_static! {
392
396
} ;
393
397
}
394
398
399
+ lazy_static ! {
400
+ static ref OMAP_SORT_U32 : OrderMap <u32 , u32 > = {
401
+ let mut map = OrderMap :: with_capacity( SORT_MAP_SIZE ) ;
402
+ for & key in & KEYS [ ..SORT_MAP_SIZE ] {
403
+ map. insert( key, key) ;
404
+ }
405
+ map
406
+ } ;
407
+ }
408
+ lazy_static ! {
409
+ static ref OMAP_SORT_S : OrderMap <String , String > = {
410
+ let mut map = OrderMap :: with_capacity( SORT_MAP_SIZE ) ;
411
+ for & key in & KEYS [ ..SORT_MAP_SIZE ] {
412
+ map. insert( format!( "{:^16x}" , & key) , String :: new( ) ) ;
413
+ }
414
+ map
415
+ } ;
416
+ }
417
+
395
418
#[ bench]
396
419
fn lookup_hashmap_100_000_multi ( b : & mut Bencher ) {
397
420
let map = & * HMAP_100K ;
@@ -643,3 +666,60 @@ fn many_retain_hashmap_100_000(b: &mut Bencher) {
643
666
map
644
667
} ) ;
645
668
}
669
+
670
+
671
+ // simple sort impl for comparison
672
+ pub fn simple_sort < K : Ord + Hash , V > ( m : & mut OrderMap < K , V > ) {
673
+ let mut ordered: Vec < _ > = m. drain ( ..) . collect ( ) ;
674
+ ordered. sort_by ( |left, right| left. 0 . cmp ( & right. 0 ) ) ;
675
+ m. extend ( ordered) ;
676
+ }
677
+
678
+
679
+ #[ bench]
680
+ fn ordermap_sort_s ( b : & mut Bencher ) {
681
+ let map = OMAP_SORT_S . clone ( ) ;
682
+
683
+ // there's a map clone there, but it's still useful to profile this
684
+ b. iter ( || {
685
+ let mut map = map. clone ( ) ;
686
+ map. sort_keys ( ) ;
687
+ map
688
+ } ) ;
689
+ }
690
+
691
+ #[ bench]
692
+ fn ordermap_simple_sort_s ( b : & mut Bencher ) {
693
+ let map = OMAP_SORT_S . clone ( ) ;
694
+
695
+ // there's a map clone there, but it's still useful to profile this
696
+ b. iter ( || {
697
+ let mut map = map. clone ( ) ;
698
+ simple_sort ( & mut map) ;
699
+ map
700
+ } ) ;
701
+ }
702
+
703
+ #[ bench]
704
+ fn ordermap_sort_u32 ( b : & mut Bencher ) {
705
+ let map = OMAP_SORT_U32 . clone ( ) ;
706
+
707
+ // there's a map clone there, but it's still useful to profile this
708
+ b. iter ( || {
709
+ let mut map = map. clone ( ) ;
710
+ map. sort_keys ( ) ;
711
+ map
712
+ } ) ;
713
+ }
714
+
715
+ #[ bench]
716
+ fn ordermap_simple_sort_u32 ( b : & mut Bencher ) {
717
+ let map = OMAP_SORT_U32 . clone ( ) ;
718
+
719
+ // there's a map clone there, but it's still useful to profile this
720
+ b. iter ( || {
721
+ let mut map = map. clone ( ) ;
722
+ simple_sort ( & mut map) ;
723
+ map
724
+ } ) ;
725
+ }
0 commit comments