summaryrefslogtreecommitdiffstats
path: root/vendor/tracing-subscriber/benches/enter.rs
blob: 49c6e730a827dd8b19e6478a4391da4b0064b585 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use criterion::{criterion_group, criterion_main, Criterion};
use tracing_subscriber::prelude::*;

fn enter(c: &mut Criterion) {
    let mut group = c.benchmark_group("enter");
    let _subscriber = tracing_subscriber::fmt()
        .with_max_level(tracing::Level::INFO)
        .finish()
        .set_default();
    group.bench_function("enabled", |b| {
        let span = tracing::info_span!("foo");
        b.iter_with_large_drop(|| span.enter())
    });
    group.bench_function("disabled", |b| {
        let span = tracing::debug_span!("foo");
        b.iter_with_large_drop(|| span.enter())
    });
}

fn enter_exit(c: &mut Criterion) {
    let mut group = c.benchmark_group("enter_exit");
    let _subscriber = tracing_subscriber::fmt()
        .with_max_level(tracing::Level::INFO)
        .finish()
        .set_default();
    group.bench_function("enabled", |b| {
        let span = tracing::info_span!("foo");
        b.iter(|| span.enter())
    });
    group.bench_function("disabled", |b| {
        let span = tracing::debug_span!("foo");
        b.iter(|| span.enter())
    });
}

fn enter_many(c: &mut Criterion) {
    let mut group = c.benchmark_group("enter_many");
    let _subscriber = tracing_subscriber::fmt()
        .with_max_level(tracing::Level::INFO)
        .finish()
        .set_default();
    group.bench_function("enabled", |b| {
        let span1 = tracing::info_span!("span1");
        let _e1 = span1.enter();
        let span2 = tracing::info_span!("span2");
        let _e2 = span2.enter();
        let span3 = tracing::info_span!("span3");
        let _e3 = span3.enter();
        let span = tracing::info_span!("foo");
        b.iter_with_large_drop(|| span.enter())
    });
    group.bench_function("disabled", |b| {
        let span1 = tracing::info_span!("span1");
        let _e1 = span1.enter();
        let span2 = tracing::info_span!("span2");
        let _e2 = span2.enter();
        let span3 = tracing::info_span!("span3");
        let _e3 = span3.enter();
        let span = tracing::debug_span!("foo");
        b.iter_with_large_drop(|| span.enter())
    });
}
criterion_group!(benches, enter, enter_exit, enter_many);
criterion_main!(benches);