Skip to content

Commit 31a3491

Browse files
utpillacijothomas
andauthored
Update metric benchmarks (open-telemetry#1907)
Co-authored-by: Cijo Thomas <[email protected]> Co-authored-by: Cijo Thomas <[email protected]>
1 parent ae6e2ff commit 31a3491

File tree

1 file changed

+50
-11
lines changed

1 file changed

+50
-11
lines changed

opentelemetry/benches/metrics.rs

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
use criterion::{criterion_group, criterion_main, Criterion};
1+
/*
2+
Benchmark Results:
3+
criterion = "0.5.1"
4+
OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
5+
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
6+
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 |
13+
| AddWithDynamicAttributes_WithStringAllocation | 77.338 ns |
14+
*/
15+
16+
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
217
use opentelemetry::{global, metrics::Counter, KeyValue};
318

419
// Run this benchmark with:
@@ -17,13 +32,13 @@ fn criterion_benchmark(c: &mut Criterion) {
1732
fn counter_add(c: &mut Criterion) {
1833
let counter = create_counter();
1934

20-
c.bench_function("Counter_NoAttributes", |b| {
35+
c.bench_function("NoAttributes", |b| {
2136
b.iter(|| {
2237
counter.add(1, &[]);
2338
});
2439
});
2540

26-
c.bench_function("Counter_AddWithInlineStaticAttributes", |b| {
41+
c.bench_function("AddWithInlineStaticAttributes", |b| {
2742
b.iter(|| {
2843
counter.add(
2944
1,
@@ -44,22 +59,46 @@ fn counter_add(c: &mut Criterion) {
4459
KeyValue::new("attribute4", "value4"),
4560
];
4661

47-
c.bench_function("Counter_AddWithStaticArray", |b| {
62+
c.bench_function("AddWithStaticArray", |b| {
4863
b.iter(|| {
4964
counter.add(1, &kv);
5065
});
5166
});
5267

53-
c.bench_function("Counter_AddWithDynamicAttributes", |b| {
68+
c.bench_function("AddWithDynamicAttributes", |b| {
69+
b.iter_batched(
70+
|| {
71+
let value1 = "value1".to_string();
72+
let value2 = "value2".to_string();
73+
let value3 = "value3".to_string();
74+
let value4 = "value4".to_string();
75+
76+
(value1, value2, value3, value4)
77+
},
78+
|values| {
79+
let kv = &[
80+
KeyValue::new("attribute1", values.0),
81+
KeyValue::new("attribute2", values.1),
82+
KeyValue::new("attribute3", values.2),
83+
KeyValue::new("attribute4", values.3),
84+
];
85+
86+
counter.add(1, kv);
87+
},
88+
BatchSize::SmallInput,
89+
);
90+
});
91+
92+
c.bench_function("AddWithDynamicAttributes_WithStringAllocation", |b| {
5493
b.iter(|| {
55-
let kv = vec![
56-
KeyValue::new("attribute1", "value1"),
57-
KeyValue::new("attribute2", "value2"),
58-
KeyValue::new("attribute3", "value3"),
59-
KeyValue::new("attribute4", "value4"),
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())),
6099
];
61100

62-
counter.add(1, &kv);
101+
counter.add(1, kv);
63102
});
64103
});
65104
}

0 commit comments

Comments
 (0)