|
1 | | -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; |
| 1 | +use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; |
2 | 2 | use futures_util::future::BoxFuture; |
3 | 3 | use opentelemetry::{ |
4 | 4 | global::BoxedTracer, |
@@ -31,22 +31,30 @@ fn criterion_benchmark(c: &mut Criterion) { |
31 | 31 | group.bench_function( |
32 | 32 | BenchmarkId::new("has_active_span", param.clone()), |
33 | 33 | |b| match api { |
34 | | - Api::Alt => b.iter(|| Context::map_current(TraceContextExt::has_active_span)), |
35 | | - Api::Spec => b.iter(|| Context::current().has_active_span()), |
| 34 | + Api::Alt => { |
| 35 | + b.iter(|| black_box(Context::map_current(TraceContextExt::has_active_span))) |
| 36 | + } |
| 37 | + Api::Spec => b.iter(|| black_box(Context::current().has_active_span())), |
36 | 38 | }, |
37 | 39 | ); |
38 | 40 | group.bench_function( |
39 | 41 | BenchmarkId::new("is_sampled", param.clone()), |
40 | 42 | |b| match api { |
41 | | - Api::Alt => { |
42 | | - b.iter(|| Context::map_current(|cx| cx.span().span_context().is_sampled())) |
| 43 | + Api::Alt => b.iter(|| { |
| 44 | + black_box(Context::map_current(|cx| { |
| 45 | + cx.span().span_context().is_sampled() |
| 46 | + })) |
| 47 | + }), |
| 48 | + Api::Spec => { |
| 49 | + b.iter(|| black_box(Context::current().span().span_context().is_sampled())) |
43 | 50 | } |
44 | | - Api::Spec => b.iter(|| Context::current().span().span_context().is_sampled()), |
45 | 51 | }, |
46 | 52 | ); |
47 | 53 | group.bench_function(BenchmarkId::new("is_recording", param), |b| match api { |
48 | | - Api::Alt => b.iter(|| Context::map_current(|cx| cx.span().is_recording())), |
49 | | - Api::Spec => b.iter(|| Context::current().span().is_recording()), |
| 54 | + Api::Alt => { |
| 55 | + b.iter(|| black_box(Context::map_current(|cx| cx.span().is_recording()))) |
| 56 | + } |
| 57 | + Api::Spec => b.iter(|| black_box(Context::current().span().is_recording())), |
50 | 58 | }); |
51 | 59 | } |
52 | 60 | } |
|
0 commit comments