Created
November 22, 2014 18:30
-
-
Save japaric/c16a573b8e371697c9f1 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
[package] | |
name = "map" | |
version = "0.0.0" | |
authors = ["Jorge Aparicio <[email protected]>"] | |
[dependencies.criterion] | |
git = "https://github.com/japaric/criterion.rs" |
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
extern crate criterion; | |
use criterion::Criterion; | |
use std::collections::{HashMap, TreeMap}; | |
use std::time::duration::Duration; | |
const SIZES: &'static [uint] = &[100, 1_000, 10_000, 100_000, 1_000_000]; | |
fn main() { | |
Criterion::default(). | |
//measurement_time(Duration::seconds(60)). | |
bench("ayosec", |b| { | |
let mut map = HashMap::new(); | |
let mut key = 0u; | |
b.iter(|| { | |
key = key + 1; | |
map.insert(key, 0u); | |
if key > 100 && key % 10 == 0 { | |
let r = key - 17; | |
map.remove(&r); | |
map.insert(key + 13, 1); | |
map.insert(key + 11, 1); | |
} | |
}) | |
}). | |
bench_with_inputs("hashmap", |b, &n| { | |
// Start with a map filled with N elements | |
let mut m: HashMap<_, _> = range(0, n).map(|i| (i, 0u)).collect(); | |
let idx = n + 1; | |
b.iter(|| { | |
m.insert(idx, 0u); | |
m.remove(&idx); | |
}) | |
}, SIZES). | |
bench_with_inputs("treemap", |b, &n| { | |
// Start with a map filled with N elements | |
let mut m: TreeMap<_, _> = range(0, n).map(|i| (i, 0u)).collect(); | |
let idx = n + 1; | |
b.iter(|| { | |
m.insert(idx, 0u); | |
m.remove(&idx); | |
}) | |
}, SIZES); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment