Skip to content

Instantly share code, notes, and snippets.

@ozkriff
Created November 12, 2018 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozkriff/ab5c414960e5352dabc48a599982e031 to your computer and use it in GitHub Desktop.
Save ozkriff/ab5c414960e5352dabc48a599982e031 to your computer and use it in GitHub Desktop.
#[macro_use]
extern crate criterion;
use std::collections::HashMap;
use criterion::Criterion;
enum Operation {
Print(&'static str),
MakeLabel(usize),
MakeJump(usize),
}
fn sort_labels(hashmap: &mut HashMap<usize, usize>, operations: Vec<Operation>) {
for (index, value) in operations.iter().enumerate() {
match value {
Operation::MakeLabel(label_id) => {
hashmap.insert(*label_id, index);
}
_operation => {}
};
}
}
fn f() -> u64 {
let operations = vec![
Operation::Print("Hello"), // Print использует &'static str
Operation::MakeLabel(0),
Operation::MakeJump(1),
Operation::Print("Не напечатается"),
Operation::MakeLabel(1),
Operation::Print("Мы здесь :)"),
];
let mut map: HashMap<usize, usize> = HashMap::new();
sort_labels(&mut map, operations);
map.len() as _
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("sort labels", |b| b.iter(|| f()));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
c bench
Finished release [optimized] target(s) in 0.09s
Running target/release/deps/criterion_test-b6d4e6c476bc742b
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Running target/release/deps/my_benchmark-a2c6c11db5814243
Gnuplot not found, disabling plotting
sort labels time: [137.35 ns 140.80 ns 144.49 ns]
change: [+14.748% +17.124% +19.501%] (p = 0.00 < 0.05)
Performance has regressed.
Found 16 outliers among 100 measurements (16.00%)
12 (12.00%) high mild
4 (4.00%) high severe
Gnuplot not found, disabling plotting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment