• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use criterion::{criterion_group, criterion_main, Criterion};
2 use tracing_subscriber::prelude::*;
3 
enter(c: &mut Criterion)4 fn enter(c: &mut Criterion) {
5     let mut group = c.benchmark_group("enter");
6     let _subscriber = tracing_subscriber::fmt()
7         .with_max_level(tracing::Level::INFO)
8         .finish()
9         .set_default();
10     group.bench_function("enabled", |b| {
11         let span = tracing::info_span!("foo");
12         b.iter_with_large_drop(|| span.enter())
13     });
14     group.bench_function("disabled", |b| {
15         let span = tracing::debug_span!("foo");
16         b.iter_with_large_drop(|| span.enter())
17     });
18 }
19 
enter_exit(c: &mut Criterion)20 fn enter_exit(c: &mut Criterion) {
21     let mut group = c.benchmark_group("enter_exit");
22     let _subscriber = tracing_subscriber::fmt()
23         .with_max_level(tracing::Level::INFO)
24         .finish()
25         .set_default();
26     group.bench_function("enabled", |b| {
27         let span = tracing::info_span!("foo");
28         b.iter(|| span.enter())
29     });
30     group.bench_function("disabled", |b| {
31         let span = tracing::debug_span!("foo");
32         b.iter(|| span.enter())
33     });
34 }
35 
enter_many(c: &mut Criterion)36 fn enter_many(c: &mut Criterion) {
37     let mut group = c.benchmark_group("enter_many");
38     let _subscriber = tracing_subscriber::fmt()
39         .with_max_level(tracing::Level::INFO)
40         .finish()
41         .set_default();
42     group.bench_function("enabled", |b| {
43         let span1 = tracing::info_span!("span1");
44         let _e1 = span1.enter();
45         let span2 = tracing::info_span!("span2");
46         let _e2 = span2.enter();
47         let span3 = tracing::info_span!("span3");
48         let _e3 = span3.enter();
49         let span = tracing::info_span!("foo");
50         b.iter_with_large_drop(|| span.enter())
51     });
52     group.bench_function("disabled", |b| {
53         let span1 = tracing::info_span!("span1");
54         let _e1 = span1.enter();
55         let span2 = tracing::info_span!("span2");
56         let _e2 = span2.enter();
57         let span3 = tracing::info_span!("span3");
58         let _e3 = span3.enter();
59         let span = tracing::debug_span!("foo");
60         b.iter_with_large_drop(|| span.enter())
61     });
62 }
63 criterion_group!(benches, enter, enter_exit, enter_many);
64 criterion_main!(benches);
65