Skip to content

Commit 09a6bea

Browse files
committed
Code changes
1 parent 1183d79 commit 09a6bea

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

opentelemetry/benches/metrics.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
55
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
66
RAM: 64.0 GB
7-
| Test | Average time|
8-
|--------------------------------|-------------|
9-
| NoAttributes | 1.1616 ns |
10-
| AddWithInlineStaticAttributes | 13.296 ns |
11-
| AddWithStaticArray | 1.1612 ns |
12-
| AddWithDynamicAttributes | 110.40 ns |
7+
| Test | Average time|
8+
|-----------------------------------------------------|-------------|
9+
| NoAttributes | 1.1616 ns |
10+
| AddWithInlineStaticAttributes | 13.296 ns |
11+
| AddWithStaticArray | 1.1612 ns |
12+
| AddWithDynamicAttributes | 110.40 ns |
13+
| AddWithDynamicAttributes_WithStringAllocation | 77.338 ns |
1314
*/
1415

15-
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
16+
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
1617
use opentelemetry::{global, metrics::Counter, KeyValue};
1718

1819
// Run this benchmark with:
@@ -87,6 +88,19 @@ fn counter_add(c: &mut Criterion) {
8788
BatchSize::SmallInput,
8889
);
8990
});
91+
92+
c.bench_function("AddWithDynamicAttributes_WithStringAllocation", |b| {
93+
b.iter(|| {
94+
let kv = &[
95+
KeyValue::new("attribute1", black_box("value1".to_string())),
96+
KeyValue::new("attribute2", black_box("value2".to_string())),
97+
KeyValue::new("attribute3", black_box("value3".to_string())),
98+
KeyValue::new("attribute4", black_box("value4".to_string())),
99+
];
100+
101+
counter.add(1, kv);
102+
});
103+
});
90104
}
91105

92106
criterion_group!(benches, criterion_benchmark);

0 commit comments

Comments
 (0)