blob: 857ad18e57e0b4a774f40ea0e7d4e8f4b7697928 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//! Compare `insert` and `insert_unique_unchecked` operations performance.
#![feature(test)]
extern crate test;
use hashbrown::HashMap;
use test::Bencher;
#[bench]
fn insert(b: &mut Bencher) {
let keys: Vec<String> = (0..1000).map(|i| format!("xxxx{}yyyy", i)).collect();
b.iter(|| {
let mut m = HashMap::with_capacity(1000);
for k in &keys {
m.insert(k, k);
}
m
});
}
#[bench]
fn insert_unique_unchecked(b: &mut Bencher) {
let keys: Vec<String> = (0..1000).map(|i| format!("xxxx{}yyyy", i)).collect();
b.iter(|| {
let mut m = HashMap::with_capacity(1000);
for k in &keys {
m.insert_unique_unchecked(k, k);
}
m
});
}
|