Skip to content

Commit

Permalink
Refactor ops benches for criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
cwlittle committed Jun 2, 2021
1 parent 363cae8 commit c833d00
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ criterion = "0.3"
[[bench]]
name = "merk"
harness = false

[[bench]]
name = "ops"
harness = false
79 changes: 48 additions & 31 deletions benches/ops.rs
Original file line number Diff line number Diff line change
@@ -1,67 +1,84 @@
#![feature(test)]

extern crate test;

use criterion::*;
use merk::owner::Owner;
use merk::test_utils::*;
use test::Bencher;

#[bench]
fn insert_1m_10k_seq_memonly(b: &mut Bencher) {
fn insert_1m_10k_seq_memonly(c: &mut Criterion) {
let initial_size = 1_000_000;
let batch_size = 10_000;

let mut tree = Owner::new(make_tree_seq(initial_size));

let mut i = initial_size / batch_size;
b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i += 1;
});
c.bench_function(
"insert_1m_10k_seq_memonly",
|b| b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i += 1;
})
);
}

#[bench]
fn insert_1m_10k_rand_memonly(b: &mut Bencher) {
fn insert_1m_10k_rand_memonly(c: &mut Criterion) {
let initial_size = 1_000_000;
let batch_size = 10_000;

let mut tree = Owner::new(make_tree_rand(initial_size, batch_size, 0));

let mut i = initial_size / batch_size;
b.iter(|| {
let batch = make_batch_rand(batch_size, i);
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i += 1;
});
c.bench_function(
"insert_1m_10k_rand_memonly",
|b| b.iter(|| {
let batch = make_batch_rand(batch_size, i);
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i += 1;
})
);
}

#[bench]
fn update_1m_10k_seq_memonly(b: &mut Bencher) {
fn update_1m_10k_seq_memonly(c: &mut Criterion) {
let initial_size = 1_000_000;
let batch_size = 10_000;

let mut tree = Owner::new(make_tree_seq(initial_size));

let mut i = 0;
b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i = (i + 1) % (initial_size / batch_size);
});
c.bench_function(
"update_1m_10k_seq_memonly",
|b| b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i = (i + 1) % (initial_size / batch_size);
})
);
}

#[bench]
fn update_1m_10k_rand_memonly(b: &mut Bencher) {
fn update_1m_10k_rand_memonly(c: &mut Criterion) {
let initial_size = 1_010_000;
let batch_size = 10_000;

let mut tree = Owner::new(make_tree_rand(initial_size, batch_size, 0));

let mut i = 0;
b.iter(|| {
let batch = make_batch_rand(batch_size, i);
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i = (i + 1) % (initial_size / batch_size);
});
c.bench_function(
"update_1m_10k_rand_memonly",
|b| b.iter(|| {
let batch = make_batch_rand(batch_size, i);
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i = (i + 1) % (initial_size / batch_size);
})
);
}

criterion_group!{
name = ops;
config = Criterion::default();
targets = insert_1m_10k_seq_memonly,
insert_1m_10k_rand_memonly,
update_1m_10k_seq_memonly,
update_1m_10k_rand_memonly,
}

criterion_main!(ops);

0 comments on commit c833d00

Please sign in to comment.