1 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; |
2 | |
3 | mod shared; |
4 | |
5 | fn bench(c: &mut Criterion) { |
6 | let mut group = c.benchmark_group("empty_span" ); |
7 | shared::for_all_dispatches(&mut group, |b| { |
8 | b.iter(|| { |
9 | let span = tracing::span::Span::none(); |
10 | black_box(&span); |
11 | }) |
12 | }); |
13 | group.bench_function("baseline_struct" , |b| { |
14 | b.iter(|| { |
15 | let span = FakeEmptySpan::new(); |
16 | black_box(&span); |
17 | }) |
18 | }); |
19 | } |
20 | |
21 | struct FakeEmptySpan { |
22 | inner: Option<(usize, std::sync::Arc<()>)>, |
23 | meta: Option<&'static ()>, |
24 | } |
25 | |
26 | impl FakeEmptySpan { |
27 | fn new() -> Self { |
28 | Self { |
29 | inner: None, |
30 | meta: None, |
31 | } |
32 | } |
33 | } |
34 | |
35 | impl Drop for FakeEmptySpan { |
36 | fn drop(&mut self) { |
37 | black_box(&self.inner); |
38 | black_box(&self.meta); |
39 | } |
40 | } |
41 | |
42 | criterion_group!(benches, bench); |
43 | criterion_main!(benches); |
44 | |