Skip to content

Commit 07a98b2

Browse files
authored
Criterion (#40)
* criterion benchmarks Signed-off-by: Yoshua Wuyts <[email protected]> * comment out full_roots tests Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent e2ddfc6 commit 07a98b2

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ repository = "https://github.com/mafintosh/flat-tree-rs"
77
keywords = ["flat", "tree", "binary"]
88
readme = "README.md"
99
license = "MIT"
10+
11+
[lib]
12+
bench = false
13+
14+
[dev-dependencies]
15+
criterion = "0.2"
16+
17+
[[bench]]
18+
name = "bench"
19+
harness = false

benches/bench.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#[macro_use]
2+
extern crate criterion;
3+
extern crate flat_tree;
4+
5+
use criterion::Criterion;
6+
7+
fn criterion_benchmark(c: &mut Criterion) {
8+
c.bench_function("children_9", |b| b.iter(|| flat_tree::children(9)));
9+
c.bench_function("children_256", |b| b.iter(|| flat_tree::children(256)));
10+
c.bench_function("count_128", |b| b.iter(|| flat_tree::count(128)));
11+
c.bench_function("depth_128", |b| b.iter(|| flat_tree::depth(128)));
12+
// c.bench_function("full_roots_16", |b| {
13+
// let mut nodes: Vec<usize> = Vec::with_capacity(16);
14+
// b.iter(|| {
15+
// flat_tree::full_roots(16, &mut nodes);
16+
// })
17+
// });
18+
// c.bench_function("full_roots_256", |b| {
19+
// let mut nodes: Vec<usize> = Vec::with_capacity(16);
20+
// b.iter(|| {
21+
// flat_tree::full_roots(256, &mut nodes);
22+
// })
23+
// });
24+
c.bench_function("index_3_1", |b| b.iter(|| flat_tree::index(3, 1)));
25+
c.bench_function("left_child_128", |b| b.iter(|| flat_tree::left_child(128)));
26+
c.bench_function("left_span_128", |b| b.iter(|| flat_tree::left_span(128)));
27+
c.bench_function("offset_128", |b| b.iter(|| flat_tree::offset(128)));
28+
c.bench_function("parent_128", |b| b.iter(|| flat_tree::parent(128)));
29+
c.bench_function("right_child_128", |b| {
30+
b.iter(|| flat_tree::right_child(128))
31+
});
32+
c.bench_function("right_span_128", |b| b.iter(|| flat_tree::right_span(128)));
33+
c.bench_function("sibling_128", |b| b.iter(|| flat_tree::sibling(128)));
34+
c.bench_function("spans_128", |b| b.iter(|| flat_tree::spans(128)));
35+
c.bench_function("uncle_128", |b| b.iter(|| flat_tree::uncle(128)));
36+
}
37+
38+
criterion_group!(benches, criterion_benchmark);
39+
criterion_main!(benches);

0 commit comments

Comments
 (0)