Skip to content

Commit 1ff14ae

Browse files
committed
Benchmarks for AnyValue
1 parent 0303a38 commit 1ff14ae

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

opentelemetry/Cargo.toml

+4
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 = "logrecord_types"
58+
harness = false
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use opentelemetry::{logs::AnyValue, Key, KeyValue};
3+
4+
// Run this benchmark with:
5+
// cargo bench --bench logrecord_types
6+
// Results:
7+
// CreateOTelKeyValue 2-3 ns
8+
// CreateOTelKeyAnyValue 30 ns
9+
// CreateTupleKeyValue < 1 ns
10+
11+
fn criterion_benchmark(c: &mut Criterion) {
12+
attributes_creation(c);
13+
}
14+
15+
fn attributes_creation(c: &mut Criterion) {
16+
c.bench_function("CreateOTelKeyValue", |b| {
17+
b.iter(|| {
18+
let _v1 = black_box(KeyValue::new("attribute1", "value1"));
19+
});
20+
});
21+
22+
c.bench_function("CreateOTelKeyAnyValue", |b| {
23+
b.iter(|| {
24+
let _k= black_box(Key::new("attribute1"));
25+
let _v1 = black_box(AnyValue::String("value1".to_string().into()));
26+
});
27+
});
28+
29+
c.bench_function("CreateTupleKeyValue", |b| {
30+
b.iter(|| {
31+
let _v1 = black_box(("attribute1", "value1"));
32+
});
33+
});
34+
}
35+
36+
criterion_group!(benches, criterion_benchmark);
37+
38+
criterion_main!(benches);

0 commit comments

Comments
 (0)