Skip to content

Commit 9d03124

Browse files
committed
Add benchmarks for dyn-traits
They are roughly half as fast due to the dynamic call overhead.
1 parent 54094b6 commit 9d03124

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

benches/usage.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use criterion::*;
22
use prodash::{
33
messages::MessageLevel,
44
tree::{root::Options as TreeOptions, Root as Tree},
5+
BoxedDynProgress,
56
};
67

78
fn usage(c: &mut Criterion) {
@@ -13,15 +14,20 @@ fn usage(c: &mut Criterion) {
1314
.create()
1415
.into()
1516
}
16-
c.benchmark_group("Tree::add_child")
17-
.throughput(Throughput::Elements(4))
18-
.bench_function("add children to build a tree of tasks and clear them (in drop)", |b| {
17+
c.benchmark_group("BoxedDynProgress::set")
18+
.throughput(Throughput::Elements(5))
19+
.bench_function("set tree 5 times", |b| {
1920
let root = small_tree();
21+
let mut progress = root.add_child("the one");
22+
progress.init(Some(20), Some("element".into()));
23+
let mut progress = BoxedDynProgress::new(progress);
24+
use prodash::Progress;
2025
b.iter(|| {
21-
let mut c = root.add_child("1");
22-
let _one = c.add_child("1");
23-
let _two = c.add_child("2");
24-
let _three = c.add_child("3");
26+
progress.set(1);
27+
progress.set(2);
28+
progress.set(3);
29+
progress.set(4);
30+
progress.set(5);
2531
});
2632
});
2733
c.benchmark_group("tree::Item::set")
@@ -38,6 +44,17 @@ fn usage(c: &mut Criterion) {
3844
progress.set(5);
3945
});
4046
});
47+
c.benchmark_group("Tree::add_child")
48+
.throughput(Throughput::Elements(4))
49+
.bench_function("add children to build a tree of tasks and clear them (in drop)", |b| {
50+
let root = small_tree();
51+
b.iter(|| {
52+
let mut c = root.add_child("1");
53+
let _one = c.add_child("1");
54+
let _two = c.add_child("2");
55+
let _three = c.add_child("3");
56+
});
57+
});
4158
c.benchmark_group("tree::Item::message")
4259
.throughput(Throughput::Elements(1))
4360
.bench_function(

0 commit comments

Comments
 (0)