-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0303a38
commit 1ff14ae
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use opentelemetry::{logs::AnyValue, Key, KeyValue}; | ||
|
||
// Run this benchmark with: | ||
// cargo bench --bench logrecord_types | ||
// Results: | ||
// CreateOTelKeyValue 2-3 ns | ||
// CreateOTelKeyAnyValue 30 ns | ||
// CreateTupleKeyValue < 1 ns | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
attributes_creation(c); | ||
} | ||
|
||
fn attributes_creation(c: &mut Criterion) { | ||
c.bench_function("CreateOTelKeyValue", |b| { | ||
b.iter(|| { | ||
let _v1 = black_box(KeyValue::new("attribute1", "value1")); | ||
}); | ||
}); | ||
|
||
c.bench_function("CreateOTelKeyAnyValue", |b| { | ||
b.iter(|| { | ||
let _k= black_box(Key::new("attribute1")); | ||
let _v1 = black_box(AnyValue::String("value1".to_string().into())); | ||
}); | ||
}); | ||
|
||
c.bench_function("CreateTupleKeyValue", |b| { | ||
b.iter(|| { | ||
let _v1 = black_box(("attribute1", "value1")); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
|
||
criterion_main!(benches); |