Skip to content

Commit 028d3e7

Browse files
authored
Benchmarks for AnyValue (#1901)
1 parent 0cfc8d9 commit 028d3e7

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

opentelemetry/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ required-features = ["metrics"]
5252
[[bench]]
5353
name = "attributes"
5454
harness = false
55+
56+
[[bench]]
57+
name = "anyvalue"
58+
harness = false

opentelemetry/benches/anyvalue.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use opentelemetry::{logs::AnyValue, Value};
3+
4+
// Run this benchmark with:
5+
// cargo bench --bench anyvalue
6+
// Results:
7+
// CreateOTelValueString 1-2 ns
8+
// CreateOTelAnyValueString 15 ns
9+
// CreateOTelValueInt 1-2 ns
10+
// CreateOTelAnyValueInt 15 ns
11+
12+
fn criterion_benchmark(c: &mut Criterion) {
13+
attributes_creation(c);
14+
}
15+
16+
fn attributes_creation(c: &mut Criterion) {
17+
c.bench_function("CreateOTelValueString", |b| {
18+
b.iter(|| {
19+
let _v = black_box(Value::String("value1".into()));
20+
});
21+
});
22+
23+
c.bench_function("CreateOTelAnyValueString", |b| {
24+
b.iter(|| {
25+
let _v = black_box(AnyValue::String("value1".into()));
26+
});
27+
});
28+
29+
c.bench_function("CreateOTelValueInt", |b| {
30+
b.iter(|| {
31+
let _v = black_box(Value::I64(123));
32+
});
33+
});
34+
35+
c.bench_function("CreateOTelAnyValueInt", |b| {
36+
b.iter(|| {
37+
let _v = black_box(AnyValue::Int(123));
38+
});
39+
});
40+
}
41+
42+
criterion_group!(benches, criterion_benchmark);
43+
44+
criterion_main!(benches);

0 commit comments

Comments
 (0)