Skip to content

Commit

Permalink
avoid intermediary
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas committed Jun 28, 2024
1 parent 1ff14ae commit f779979
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions opentelemetry/benches/logrecord_types.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use opentelemetry::{logs::AnyValue, Key, KeyValue};
use opentelemetry::{logs::AnyValue, Key, KeyValue, Value};

// Run this benchmark with:
// cargo bench --bench logrecord_types
// Results:
// CreateOTelKeyValue 2-3 ns
// CreateOTelKeyAnyValue 30 ns
// CreateOTelKeyAnyValue 15 ns
// CreateTupleKeyValue < 1 ns

fn criterion_benchmark(c: &mut Criterion) {
Expand All @@ -15,14 +15,15 @@ fn criterion_benchmark(c: &mut Criterion) {
fn attributes_creation(c: &mut Criterion) {
c.bench_function("CreateOTelKeyValue", |b| {
b.iter(|| {
let _v1 = black_box(KeyValue::new("attribute1", "value1"));
let _k1 = black_box(Key::new("attribute1"));
let _v2 = black_box(Value::String("value1".into()));
});
});

c.bench_function("CreateOTelKeyAnyValue", |b| {
b.iter(|| {
let _k= black_box(Key::new("attribute1"));
let _v1 = black_box(AnyValue::String("value1".to_string().into()));
let _v1 = black_box(AnyValue::String("value1".into()));
});
});

Expand Down

0 comments on commit f779979

Please sign in to comment.