Skip to content

Commit 3b0b587

Browse files
committed
Update benchmarks
1 parent 7d4185f commit 3b0b587

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

benches/bench.rs

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This benchmark suite contains some benchmarks along a set of dimensions:
2-
// Hasher: std default (SipHash) and crate default (FxHash).
2+
// Hasher: std default (SipHash) and crate default (AHash).
33
// Int key distribution: low bit heavy, top bit heavy, and random.
44
// Task: basic functionality: insert, insert_erase, lookup, lookup_fail, iter
55
#![feature(test)]
@@ -15,7 +15,7 @@ use std::collections::hash_map::RandomState;
1515
const SIZE: usize = 1000;
1616

1717
// The default hashmap when using this crate directly.
18-
type FxHashMap<K, V> = HashMap<K, V, DefaultHashBuilder>;
18+
type AHashMap<K, V> = HashMap<K, V, DefaultHashBuilder>;
1919
// This uses the hashmap from this crate with the default hasher of the stdlib.
2020
type StdHashMap<K, V> = HashMap<K, V, RandomState>;
2121

@@ -41,18 +41,22 @@ impl Iterator for RandomKeys {
4141
}
4242

4343
macro_rules! bench_suite {
44-
($bench_macro:ident, $bench_fx_serial:ident, $bench_std_serial:ident,
45-
$bench_fx_highbits:ident, $bench_std_highbits:ident,
46-
$bench_fx_random:ident, $bench_std_random:ident) => {
47-
$bench_macro!($bench_fx_serial, FxHashMap, 0..);
44+
($bench_macro:ident, $bench_ahash_serial:ident, $bench_std_serial:ident,
45+
$bench_ahash_highbits:ident, $bench_std_highbits:ident,
46+
$bench_ahash_random:ident, $bench_std_random:ident) => {
47+
$bench_macro!($bench_ahash_serial, AHashMap, 0..);
4848
$bench_macro!($bench_std_serial, StdHashMap, 0..);
49-
$bench_macro!($bench_fx_highbits, FxHashMap, (0..).map(usize::swap_bytes));
49+
$bench_macro!(
50+
$bench_ahash_highbits,
51+
AHashMap,
52+
(0..).map(usize::swap_bytes)
53+
);
5054
$bench_macro!(
5155
$bench_std_highbits,
5256
StdHashMap,
5357
(0..).map(usize::swap_bytes)
5458
);
55-
$bench_macro!($bench_fx_random, FxHashMap, RandomKeys::new());
59+
$bench_macro!($bench_ahash_random, AHashMap, RandomKeys::new());
5660
$bench_macro!($bench_std_random, StdHashMap, RandomKeys::new());
5761
};
5862
}
@@ -61,56 +65,60 @@ macro_rules! bench_insert {
6165
($name:ident, $maptype:ident, $keydist:expr) => {
6266
#[bench]
6367
fn $name(b: &mut Bencher) {
68+
let mut m = $maptype::with_capacity_and_hasher(SIZE, Default::default());
6469
b.iter(|| {
65-
let mut m = $maptype::default();
70+
m.clear();
6671
for i in ($keydist).take(SIZE) {
6772
m.insert(i, i);
6873
}
69-
black_box(m);
74+
black_box(&mut m);
7075
})
7176
}
7277
};
7378
}
7479

7580
bench_suite!(
7681
bench_insert,
77-
insert_fx_serial,
82+
insert_ahash_serial,
7883
insert_std_serial,
79-
insert_fx_highbits,
84+
insert_ahash_highbits,
8085
insert_std_highbits,
81-
insert_fx_random,
86+
insert_ahash_random,
8287
insert_std_random
8388
);
8489

8590
macro_rules! bench_insert_erase {
8691
($name:ident, $maptype:ident, $keydist:expr) => {
8792
#[bench]
8893
fn $name(b: &mut Bencher) {
89-
let mut m = $maptype::default();
90-
let mut add_iter = $keydist;
91-
for i in (&mut add_iter).take(SIZE) {
92-
m.insert(i, i);
94+
let mut base = $maptype::default();
95+
for i in ($keydist).take(SIZE) {
96+
base.insert(i, i);
9397
}
94-
let mut remove_iter = $keydist;
98+
let skip = $keydist.skip(SIZE);
9599
b.iter(|| {
100+
let mut m = base.clone();
101+
let mut add_iter = skip.clone();
102+
let mut remove_iter = $keydist;
96103
// While keeping the size constant,
97104
// replace the first keydist with the second.
98105
for (add, remove) in (&mut add_iter).zip(&mut remove_iter).take(SIZE) {
99106
m.insert(add, add);
100107
black_box(m.remove(&remove));
101108
}
109+
black_box(m);
102110
})
103111
}
104112
};
105113
}
106114

107115
bench_suite!(
108116
bench_insert_erase,
109-
insert_erase_fx_serial,
117+
insert_erase_ahash_serial,
110118
insert_erase_std_serial,
111-
insert_erase_fx_highbits,
119+
insert_erase_ahash_highbits,
112120
insert_erase_std_highbits,
113-
insert_erase_fx_random,
121+
insert_erase_ahash_random,
114122
insert_erase_std_random
115123
);
116124

@@ -134,11 +142,11 @@ macro_rules! bench_lookup {
134142

135143
bench_suite!(
136144
bench_lookup,
137-
lookup_fx_serial,
145+
lookup_ahash_serial,
138146
lookup_std_serial,
139-
lookup_fx_highbits,
147+
lookup_ahash_highbits,
140148
lookup_std_highbits,
141-
lookup_fx_random,
149+
lookup_ahash_random,
142150
lookup_std_random
143151
);
144152

@@ -163,11 +171,11 @@ macro_rules! bench_lookup_fail {
163171

164172
bench_suite!(
165173
bench_lookup_fail,
166-
lookup_fail_fx_serial,
174+
lookup_fail_ahash_serial,
167175
lookup_fail_std_serial,
168-
lookup_fail_fx_highbits,
176+
lookup_fail_ahash_highbits,
169177
lookup_fail_std_highbits,
170-
lookup_fail_fx_random,
178+
lookup_fail_ahash_random,
171179
lookup_fail_std_random
172180
);
173181

@@ -191,10 +199,10 @@ macro_rules! bench_iter {
191199

192200
bench_suite!(
193201
bench_iter,
194-
iter_fx_serial,
202+
iter_ahash_serial,
195203
iter_std_serial,
196-
iter_fx_highbits,
204+
iter_ahash_highbits,
197205
iter_std_highbits,
198-
iter_fx_random,
206+
iter_ahash_random,
199207
iter_std_random
200208
);

0 commit comments

Comments
 (0)