Skip to content

Instantly share code, notes, and snippets.

@nonsensecreativity
Forked from jedisct1/test.rs
Created December 21, 2017 13:30
Show Gist options
  • Save nonsensecreativity/4ab0bda9d4093f9b16ae0a242c041cc4 to your computer and use it in GitHub Desktop.
Save nonsensecreativity/4ab0bda9d4093f9b16ae0a242c041cc4 to your computer and use it in GitHub Desktop.
use ::Trie;
use _test::Bencher;
use std::collections::*;
#[bench]
fn bench_qptrie_insert(b: &mut Bencher) {
let mut trie = Trie::default();
let a = 1_234;
let mut x = 0;
b.iter(move || for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.insert(key, ());
})
}
#[bench]
fn bench_qptrie_get(b: &mut Bencher) {
let mut trie = Trie::default();
let a = 1_234;
let mut x = 0;
for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.insert(key, ());
}
b.iter(move || for _ in 0..499_979 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.get(&key).unwrap();
})
}
#[bench]
fn bench_btreemap_insert(b: &mut Bencher) {
let mut trie = BTreeMap::default();
let a = 1_234;
let mut x = 0;
b.iter(|| for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.insert(key, ());
})
}
#[bench]
fn bench_btreemap_get(b: &mut Bencher) {
let mut trie = BTreeMap::default();
let a = 1_234;
let mut x = 0;
for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.insert(key, ());
}
b.iter(move || for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.get(&key).unwrap();
})
}
#[bench]
fn bench_hashmap_insert(b: &mut Bencher) {
let mut trie: HashMap<[u8; 4], ()> = HashMap::default();
let a = 1_234;
let mut x = 0;
b.iter(move || for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.insert(key, ());
})
}
#[bench]
fn bench_hashmap_get(b: &mut Bencher) {
let mut trie: HashMap<[u8; 4], ()> = HashMap::default();
let a = 1_234;
let mut x = 0;
for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.insert(key, ());
}
b.iter(move || for _ in 0..499_980 {
x = (x + a) % 499_979;
let key = [x as u8, (x >> 8) as u8, (x >> 16) as u8, (x >> 24) as u8];
trie.get(&key).unwrap();
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment