Skip to content

Commit

Permalink
Benchmarks for AnyValue (#1901)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jul 1, 2024
1 parent 0cfc8d9 commit 028d3e7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ required-features = ["metrics"]
[[bench]]
name = "attributes"
harness = false

[[bench]]
name = "anyvalue"
harness = false
44 changes: 44 additions & 0 deletions opentelemetry/benches/anyvalue.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use opentelemetry::{logs::AnyValue, Value};

// Run this benchmark with:
// cargo bench --bench anyvalue
// Results:
// CreateOTelValueString 1-2 ns
// CreateOTelAnyValueString 15 ns
// CreateOTelValueInt 1-2 ns
// CreateOTelAnyValueInt 15 ns

fn criterion_benchmark(c: &mut Criterion) {
attributes_creation(c);
}

fn attributes_creation(c: &mut Criterion) {
c.bench_function("CreateOTelValueString", |b| {
b.iter(|| {
let _v = black_box(Value::String("value1".into()));
});
});

c.bench_function("CreateOTelAnyValueString", |b| {
b.iter(|| {
let _v = black_box(AnyValue::String("value1".into()));
});
});

c.bench_function("CreateOTelValueInt", |b| {
b.iter(|| {
let _v = black_box(Value::I64(123));
});
});

c.bench_function("CreateOTelAnyValueInt", |b| {
b.iter(|| {
let _v = black_box(AnyValue::Int(123));
});
});
}

criterion_group!(benches, criterion_benchmark);

criterion_main!(benches);

0 comments on commit 028d3e7

Please sign in to comment.