Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the map core to its own module #125

Merged
merged 12 commits into from
Jun 9, 2020
104 changes: 52 additions & 52 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn new_hashmap(b: &mut Bencher) {
}

#[bench]
fn new_orderedmap(b: &mut Bencher) {
fn new_indexmap(b: &mut Bencher) {
b.iter(|| IndexMap::<String, String>::new());
}

Expand All @@ -40,7 +40,7 @@ fn with_capacity_10e5_hashmap(b: &mut Bencher) {
}

#[bench]
fn with_capacity_10e5_orderedmap(b: &mut Bencher) {
fn with_capacity_10e5_indexmap(b: &mut Bencher) {
b.iter(|| IndexMap::<String, String>::with_capacity(10_000));
}

Expand All @@ -57,7 +57,7 @@ fn insert_hashmap_10_000(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_10_000(b: &mut Bencher) {
fn insert_indexmap_10_000(b: &mut Bencher) {
let c = 10_000;
b.iter(|| {
let mut map = IndexMap::with_capacity(c);
Expand All @@ -81,7 +81,7 @@ fn insert_hashmap_string_10_000(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_string_10_000(b: &mut Bencher) {
fn insert_indexmap_string_10_000(b: &mut Bencher) {
let c = 10_000;
b.iter(|| {
let mut map = IndexMap::with_capacity(c);
Expand All @@ -106,7 +106,7 @@ fn insert_hashmap_str_10_000(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_str_10_000(b: &mut Bencher) {
fn insert_indexmap_str_10_000(b: &mut Bencher) {
let c = 10_000;
let ss = Vec::from_iter((0..c).map(|x| x.to_string()));
b.iter(|| {
Expand All @@ -132,7 +132,7 @@ fn insert_hashmap_int_bigvalue_10_000(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_int_bigvalue_10_000(b: &mut Bencher) {
fn insert_indexmap_int_bigvalue_10_000(b: &mut Bencher) {
let c = 10_000;
let value = [0u64; 10];
b.iter(|| {
Expand All @@ -157,7 +157,7 @@ fn insert_hashmap_100_000(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_100_000(b: &mut Bencher) {
fn insert_indexmap_100_000(b: &mut Bencher) {
let c = 100_000;
b.iter(|| {
let mut map = IndexMap::with_capacity(c);
Expand All @@ -181,7 +181,7 @@ fn insert_hashmap_150(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_150(b: &mut Bencher) {
fn insert_indexmap_150(b: &mut Bencher) {
let c = 150;
b.iter(|| {
let mut map = IndexMap::with_capacity(c);
Expand All @@ -205,7 +205,7 @@ fn entry_hashmap_150(b: &mut Bencher) {
}

#[bench]
fn entry_orderedmap_150(b: &mut Bencher) {
fn entry_indexmap_150(b: &mut Bencher) {
let c = 150;
b.iter(|| {
let mut map = IndexMap::with_capacity(c);
Expand All @@ -229,7 +229,7 @@ fn iter_sum_hashmap_10_000(b: &mut Bencher) {
}

#[bench]
fn iter_sum_orderedmap_10_000(b: &mut Bencher) {
fn iter_sum_indexmap_10_000(b: &mut Bencher) {
let c = 10_000;
let mut map = IndexMap::with_capacity(c);
let len = c - c / 10;
Expand Down Expand Up @@ -257,7 +257,7 @@ fn iter_black_box_hashmap_10_000(b: &mut Bencher) {
}

#[bench]
fn iter_black_box_orderedmap_10_000(b: &mut Bencher) {
fn iter_black_box_indexmap_10_000(b: &mut Bencher) {
let c = 10_000;
let mut map = IndexMap::with_capacity(c);
let len = c - c / 10;
Expand Down Expand Up @@ -317,7 +317,7 @@ fn lookup_hashmap_10_000_noexist(b: &mut Bencher) {
}

#[bench]
fn lookup_orderedmap_10_000_exist(b: &mut Bencher) {
fn lookup_indexmap_10_000_exist(b: &mut Bencher) {
let c = 10_000;
let mut map = IndexMap::with_capacity(c);
let keys = shuffled_keys(0..c);
Expand All @@ -334,7 +334,7 @@ fn lookup_orderedmap_10_000_exist(b: &mut Bencher) {
}

#[bench]
fn lookup_orderedmap_10_000_noexist(b: &mut Bencher) {
fn lookup_indexmap_10_000_noexist(b: &mut Bencher) {
let c = 10_000;
let mut map = IndexMap::with_capacity(c);
let keys = shuffled_keys(0..c);
Expand All @@ -357,7 +357,7 @@ const SORT_MAP_SIZE: usize = 10_000;

// use lazy_static so that comparison benchmarks use the exact same inputs
lazy_static! {
static ref KEYS: Vec<u32> = { shuffled_keys(0..LOOKUP_MAP_SIZE) };
static ref KEYS: Vec<u32> = shuffled_keys(0..LOOKUP_MAP_SIZE);
}

lazy_static! {
Expand All @@ -373,7 +373,7 @@ lazy_static! {
}

lazy_static! {
static ref OMAP_100K: IndexMap<u32, u32> = {
static ref IMAP_100K: IndexMap<u32, u32> = {
let c = LOOKUP_MAP_SIZE;
let mut map = IndexMap::with_capacity(c as usize);
let keys = &*KEYS;
Expand All @@ -385,7 +385,7 @@ lazy_static! {
}

lazy_static! {
static ref OMAP_SORT_U32: IndexMap<u32, u32> = {
static ref IMAP_SORT_U32: IndexMap<u32, u32> = {
let mut map = IndexMap::with_capacity(SORT_MAP_SIZE);
for &key in &KEYS[..SORT_MAP_SIZE] {
map.insert(key, key);
Expand All @@ -394,7 +394,7 @@ lazy_static! {
};
}
lazy_static! {
static ref OMAP_SORT_S: IndexMap<String, String> = {
static ref IMAP_SORT_S: IndexMap<String, String> = {
let mut map = IndexMap::with_capacity(SORT_MAP_SIZE);
for &key in &KEYS[..SORT_MAP_SIZE] {
map.insert(format!("{:^16x}", &key), String::new());
Expand All @@ -416,8 +416,8 @@ fn lookup_hashmap_100_000_multi(b: &mut Bencher) {
}

#[bench]
fn lookup_ordermap_100_000_multi(b: &mut Bencher) {
let map = &*OMAP_100K;
fn lookup_indexmap_100_000_multi(b: &mut Bencher) {
let map = &*IMAP_100K;
b.iter(|| {
let mut found = 0;
for key in 0..LOOKUP_SAMPLE_SIZE {
Expand All @@ -442,8 +442,8 @@ fn lookup_hashmap_100_000_inorder_multi(b: &mut Bencher) {
}

#[bench]
fn lookup_ordermap_100_000_inorder_multi(b: &mut Bencher) {
let map = &*OMAP_100K;
fn lookup_indexmap_100_000_inorder_multi(b: &mut Bencher) {
let map = &*IMAP_100K;
let keys = &*KEYS;
b.iter(|| {
let mut found = 0;
Expand All @@ -465,8 +465,8 @@ fn lookup_hashmap_100_000_single(b: &mut Bencher) {
}

#[bench]
fn lookup_ordermap_100_000_single(b: &mut Bencher) {
let map = &*OMAP_100K;
fn lookup_indexmap_100_000_single(b: &mut Bencher) {
let map = &*IMAP_100K;
let mut iter = (0..LOOKUP_MAP_SIZE + LOOKUP_SAMPLE_SIZE).cycle();
b.iter(|| {
let key = iter.next().unwrap();
Expand All @@ -490,7 +490,7 @@ fn grow_fnv_hashmap_100_000(b: &mut Bencher) {
}

#[bench]
fn grow_fnv_ordermap_100_000(b: &mut Bencher) {
fn grow_fnv_indexmap_100_000(b: &mut Bencher) {
b.iter(|| {
let mut map: IndexMap<_, _, FnvBuilder> = IndexMap::default();
for x in 0..GROW_SIZE {
Expand Down Expand Up @@ -529,7 +529,7 @@ fn hashmap_merge_shuffle(b: &mut Bencher) {
}

#[bench]
fn ordermap_merge_simple(b: &mut Bencher) {
fn indexmap_merge_simple(b: &mut Bencher) {
let first_map: IndexMap<u64, _> = (0..MERGE).map(|i| (i, ())).collect();
let second_map: IndexMap<u64, _> = (MERGE..MERGE * 2).map(|i| (i, ())).collect();
b.iter(|| {
Expand All @@ -540,7 +540,7 @@ fn ordermap_merge_simple(b: &mut Bencher) {
}

#[bench]
fn ordermap_merge_shuffle(b: &mut Bencher) {
fn indexmap_merge_shuffle(b: &mut Bencher) {
let first_map: IndexMap<u64, _> = (0..MERGE).map(|i| (i, ())).collect();
let second_map: IndexMap<u64, _> = (MERGE..MERGE * 2).map(|i| (i, ())).collect();
let mut v = Vec::new();
Expand All @@ -556,8 +556,8 @@ fn ordermap_merge_shuffle(b: &mut Bencher) {
}

#[bench]
fn swap_remove_ordermap_100_000(b: &mut Bencher) {
let map = OMAP_100K.clone();
fn swap_remove_indexmap_100_000(b: &mut Bencher) {
let map = IMAP_100K.clone();
let mut keys = Vec::from_iter(map.keys().cloned());
let mut rng = SmallRng::from_entropy();
keys.shuffle(&mut rng);
Expand All @@ -573,8 +573,8 @@ fn swap_remove_ordermap_100_000(b: &mut Bencher) {
}

#[bench]
fn shift_remove_ordermap_100_000_few(b: &mut Bencher) {
let map = OMAP_100K.clone();
fn shift_remove_indexmap_100_000_few(b: &mut Bencher) {
let map = IMAP_100K.clone();
let mut keys = Vec::from_iter(map.keys().cloned());
let mut rng = SmallRng::from_entropy();
keys.shuffle(&mut rng);
Expand All @@ -585,13 +585,13 @@ fn shift_remove_ordermap_100_000_few(b: &mut Bencher) {
for key in &keys {
map.shift_remove(key);
}
assert_eq!(map.len(), OMAP_100K.len() - keys.len());
assert_eq!(map.len(), IMAP_100K.len() - keys.len());
map
});
}

#[bench]
fn shift_remove_ordermap_2_000_full(b: &mut Bencher) {
fn shift_remove_indexmap_2_000_full(b: &mut Bencher) {
let mut keys = KEYS[..2_000].to_vec();
let mut map = IndexMap::with_capacity(keys.len());
for &key in &keys {
Expand All @@ -611,8 +611,8 @@ fn shift_remove_ordermap_2_000_full(b: &mut Bencher) {
}

#[bench]
fn pop_ordermap_100_000(b: &mut Bencher) {
let map = OMAP_100K.clone();
fn pop_indexmap_100_000(b: &mut Bencher) {
let map = IMAP_100K.clone();

b.iter(|| {
let mut map = map.clone();
Expand All @@ -625,8 +625,8 @@ fn pop_ordermap_100_000(b: &mut Bencher) {
}

#[bench]
fn few_retain_ordermap_100_000(b: &mut Bencher) {
let map = OMAP_100K.clone();
fn few_retain_indexmap_100_000(b: &mut Bencher) {
let map = IMAP_100K.clone();

b.iter(|| {
let mut map = map.clone();
Expand All @@ -647,8 +647,8 @@ fn few_retain_hashmap_100_000(b: &mut Bencher) {
}

#[bench]
fn half_retain_ordermap_100_000(b: &mut Bencher) {
let map = OMAP_100K.clone();
fn half_retain_indexmap_100_000(b: &mut Bencher) {
let map = IMAP_100K.clone();

b.iter(|| {
let mut map = map.clone();
Expand All @@ -669,8 +669,8 @@ fn half_retain_hashmap_100_000(b: &mut Bencher) {
}

#[bench]
fn many_retain_ordermap_100_000(b: &mut Bencher) {
let map = OMAP_100K.clone();
fn many_retain_indexmap_100_000(b: &mut Bencher) {
let map = IMAP_100K.clone();

b.iter(|| {
let mut map = map.clone();
Expand Down Expand Up @@ -698,8 +698,8 @@ pub fn simple_sort<K: Ord + Hash, V>(m: &mut IndexMap<K, V>) {
}

#[bench]
fn ordermap_sort_s(b: &mut Bencher) {
let map = OMAP_SORT_S.clone();
fn indexmap_sort_s(b: &mut Bencher) {
let map = IMAP_SORT_S.clone();

// there's a map clone there, but it's still useful to profile this
b.iter(|| {
Expand All @@ -710,8 +710,8 @@ fn ordermap_sort_s(b: &mut Bencher) {
}

#[bench]
fn ordermap_simple_sort_s(b: &mut Bencher) {
let map = OMAP_SORT_S.clone();
fn indexmap_simple_sort_s(b: &mut Bencher) {
let map = IMAP_SORT_S.clone();

// there's a map clone there, but it's still useful to profile this
b.iter(|| {
Expand All @@ -722,8 +722,8 @@ fn ordermap_simple_sort_s(b: &mut Bencher) {
}

#[bench]
fn ordermap_sort_u32(b: &mut Bencher) {
let map = OMAP_SORT_U32.clone();
fn indexmap_sort_u32(b: &mut Bencher) {
let map = IMAP_SORT_U32.clone();

// there's a map clone there, but it's still useful to profile this
b.iter(|| {
Expand All @@ -734,8 +734,8 @@ fn ordermap_sort_u32(b: &mut Bencher) {
}

#[bench]
fn ordermap_simple_sort_u32(b: &mut Bencher) {
let map = OMAP_SORT_U32.clone();
fn indexmap_simple_sort_u32(b: &mut Bencher) {
let map = IMAP_SORT_U32.clone();

// there's a map clone there, but it's still useful to profile this
b.iter(|| {
Expand All @@ -747,15 +747,15 @@ fn ordermap_simple_sort_u32(b: &mut Bencher) {

// measure the fixed overhead of cloning in sort benchmarks
#[bench]
fn ordermap_clone_for_sort_s(b: &mut Bencher) {
let map = OMAP_SORT_S.clone();
fn indexmap_clone_for_sort_s(b: &mut Bencher) {
let map = IMAP_SORT_S.clone();

b.iter(|| map.clone());
}

#[bench]
fn ordermap_clone_for_sort_u32(b: &mut Bencher) {
let map = OMAP_SORT_U32.clone();
fn indexmap_clone_for_sort_u32(b: &mut Bencher) {
let map = IMAP_SORT_U32.clone();

b.iter(|| map.clone());
}
6 changes: 3 additions & 3 deletions benches/faststring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn insert_hashmap_string_oneshot_10_000(b: &mut Bencher) {
}

#[bench]
fn insert_orderedmap_string_10_000(b: &mut Bencher) {
fn insert_indexmap_string_10_000(b: &mut Bencher) {
let c = 10_000;
b.iter(|| {
let mut map = IndexMap::with_capacity(c);
Expand Down Expand Up @@ -144,7 +144,7 @@ fn lookup_hashmap_10_000_exist_string_oneshot(b: &mut Bencher) {
}

#[bench]
fn lookup_ordermap_10_000_exist_string(b: &mut Bencher) {
fn lookup_indexmap_10_000_exist_string(b: &mut Bencher) {
let c = 10_000;
let mut map = IndexMap::with_capacity(c);
let keys = shuffled_keys(0..c);
Expand All @@ -162,7 +162,7 @@ fn lookup_ordermap_10_000_exist_string(b: &mut Bencher) {
}

#[bench]
fn lookup_ordermap_10_000_exist_string_oneshot(b: &mut Bencher) {
fn lookup_indexmap_10_000_exist_string_oneshot(b: &mut Bencher) {
let c = 10_000;
let mut map = IndexMap::with_capacity(c);
let keys = shuffled_keys(0..c);
Expand Down
Loading