Skip to content

Commit

Permalink
Add benchmarks (#2080)
Browse files Browse the repository at this point in the history
  • Loading branch information
utpilla authored Sep 4, 2024
1 parent 3aa5026 commit 4a86e16
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions opentelemetry/benches/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/* OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
RAM: 64.0 GB
| Test | Average time|
|--------------------------------|-------------|
| CreateOTelKey_Static | 1.2 ns |
| CreateOTelKey_Owned | 12.6 ns |
| CreateOTelKey_Arc | 23.35 ns |
| CreateOTelKeyValue | 3.24 ns |
| CreateTupleKeyValue | 671 ps |
| CreateOtelKeyValueArray | 18.4 ns |
| CreateTupleKeyValueArray | 2.73 ns |
| Test | Average time|
|--------------------------------------------------|-------------|
| CreateOTelKey_Static | 1.2 ns |
| CreateOTelKey_Owned | 12.6 ns |
| CreateOTelKey_Arc | 23.35 ns |
| CreateOTelKeyValue | 3.24 ns |
| CreateTupleKeyValue | 671 ps |
| CreateOtelKeyValueArray | 18.4 ns |
| CreateOtelKeyValueArrayWithMixedValueTypes | 18.1 ns |
| CreateOtelKeyValueArrayWithNonStaticValues | 90.1 ns |
| CreateTupleKeyValueArray | 2.73 ns |
*/

use criterion::{black_box, criterion_group, criterion_main, Criterion};
Expand Down Expand Up @@ -65,6 +67,30 @@ fn attributes_creation(c: &mut Criterion) {
});
});

c.bench_function("CreateOtelKeyValueArrayWithMixedValueTypes", |b| {
b.iter(|| {
let _v1 = black_box([
KeyValue::new("attribute1", true),
KeyValue::new("attribute2", 100),
KeyValue::new("attribute3", 100.5),
KeyValue::new("attribute4", "value"),
]);
});
});

let value = "value1value2value3value4".to_owned();

c.bench_function("CreateOtelKeyValueArrayWithNonStaticValues", |b| {
b.iter(|| {
let _v1 = black_box([
KeyValue::new("attribute1", value[0..6].to_owned()), // value[0..6] = "value1"
KeyValue::new("attribute2", value[6..12].to_owned()), // value[6..12] = "value2"
KeyValue::new("attribute3", value[12..18].to_owned()), // value[12..18] = "value3"
KeyValue::new("attribute4", value[18..24].to_owned()), // value[18..24] = "value4"
]);
});
});

c.bench_function("CreateTupleKeyValueArray", |b| {
b.iter(|| {
let _v1 = black_box([
Expand Down

0 comments on commit 4a86e16

Please sign in to comment.