Created
December 8, 2016 13:18
-
-
Save jedisct1/ce89f94dda19ca426110c7f82405ad45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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