Skip to content

Commit 1b86d3b

Browse files
committed
Update benchmarks
1 parent e05979d commit 1b86d3b

File tree

2 files changed

+143
-15
lines changed

2 files changed

+143
-15
lines changed

opentelemetry-sdk/benches/metrics_counter.rs

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
/*
22
The benchmark results:
33
criterion = "0.5.1"
4-
rustc 1.82.0 (f6e511eec 2024-10-15)
5-
OS: Ubuntu 22.04.3 LTS (5.15.167.4-microsoft-standard-WSL2)
6-
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
4+
rustc 1.83.0 (90b35a623 2024-11-26)
5+
OS: Ubuntu 22.04.4 LTS (5.15.167.4-microsoft-standard-WSL2)
6+
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz 2.79 GHz
77
RAM: 64.0 GB
8-
| Test | Average time|
9-
|--------------------------------|-------------|
10-
| Counter_Add_Sorted | 172 ns |
11-
| Counter_Add_Unsorted | 183 ns |
12-
| Counter_Overflow | 562 ns |
13-
| ThreadLocal_Random_Generator_5 | 37 ns |
8+
| Test | Average time|
9+
|-------------------------------------------------------|-------------|
10+
| Counter_Add_Sorted | 160 ns |
11+
| Counter_Add_Unsorted | 164 ns |
12+
| Counter_Add_Sorted_With_Non_Static_Values | 439 ns |
13+
| Counter_Overflow | 562 ns |
14+
| ThreadLocal_Random_Generator_5 | 37 ns |
1415
*/
1516

1617
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
@@ -51,6 +52,7 @@ fn create_counter(name: &'static str) -> Counter<u64> {
5152
fn criterion_benchmark(c: &mut Criterion) {
5253
counter_add_sorted(c);
5354
counter_add_unsorted(c);
55+
counter_add_sorted_with_non_static_values(c);
5456
counter_overflow(c);
5557
random_generator(c);
5658
}
@@ -127,6 +129,68 @@ fn counter_add_unsorted(c: &mut Criterion) {
127129
});
128130
}
129131

132+
fn counter_add_sorted_with_non_static_values(c: &mut Criterion) {
133+
let counter = create_counter("Counter_Add_Sorted_With_Non_Static_Values");
134+
c.bench_function("Counter_Add_Sorted_With_Non_Static_Values", |b| {
135+
b.iter_batched(
136+
|| {
137+
(
138+
[
139+
"value1".to_owned(),
140+
"value2".to_owned(),
141+
"value3".to_owned(),
142+
"value4".to_owned(),
143+
"value5".to_owned(),
144+
"value6".to_owned(),
145+
"value7".to_owned(),
146+
"value8".to_owned(),
147+
"value9".to_owned(),
148+
"value10".to_owned(),
149+
],
150+
// 4*4*10*10 = 1600 time series.
151+
CURRENT_RNG.with(|rng| {
152+
let mut rng = rng.borrow_mut();
153+
[
154+
rng.gen_range(0..4),
155+
rng.gen_range(0..4),
156+
rng.gen_range(0..10),
157+
rng.gen_range(0..10),
158+
]
159+
}),
160+
)
161+
},
162+
|(attribute_values, rands)| {
163+
let index_first_attribute = rands[0];
164+
let index_second_attribute = rands[1];
165+
let index_third_attribute = rands[2];
166+
let index_fourth_attribute = rands[3];
167+
counter.add(
168+
1,
169+
&[
170+
KeyValue::new(
171+
"attribute1",
172+
attribute_values[index_first_attribute].as_str().to_owned(),
173+
),
174+
KeyValue::new(
175+
"attribute2",
176+
attribute_values[index_second_attribute].as_str().to_owned(),
177+
),
178+
KeyValue::new(
179+
"attribute3",
180+
attribute_values[index_third_attribute].as_str().to_owned(),
181+
),
182+
KeyValue::new(
183+
"attribute4",
184+
attribute_values[index_fourth_attribute].as_str().to_owned(),
185+
),
186+
],
187+
);
188+
},
189+
BatchSize::SmallInput,
190+
);
191+
});
192+
}
193+
130194
fn counter_overflow(c: &mut Criterion) {
131195
let counter = create_counter("Counter_Overflow");
132196
// Cause overflow.

opentelemetry-sdk/benches/metrics_histogram.rs

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
/*
22
The benchmark results:
33
criterion = "0.5.1"
4-
rustc 1.82.0 (f6e511eec 2024-10-15)
4+
rustc 1.83.0 (90b35a623 2024-11-26)
55
OS: Ubuntu 22.04.4 LTS (5.15.167.4-microsoft-standard-WSL2)
6-
Hardware: AMD EPYC 7763 64-Core Processor - 2.44 GHz, 16vCPUs,
6+
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz 2.79 GHz
77
RAM: 64.0 GB
8-
| Test | Average time|
9-
|--------------------------------|-------------|
10-
| Histogram_Record | 225.04 ns |
8+
| Test | Average time|
9+
|-------------------------------------------------------|-------------|
10+
| Histogram_Record | 206.35 ns |
11+
| Histogram_Record_With_Non_Static_Values | 483.58 ns |
1112
1213
*/
1314

14-
use criterion::{criterion_group, criterion_main, Criterion};
15+
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
1516
use opentelemetry::{
1617
metrics::{Histogram, MeterProvider as _},
1718
KeyValue,
@@ -48,6 +49,7 @@ fn create_histogram(name: &'static str) -> Histogram<u64> {
4849

4950
fn criterion_benchmark(c: &mut Criterion) {
5051
histogram_record(c);
52+
histogram_record_with_non_static_values(c);
5153
}
5254

5355
fn histogram_record(c: &mut Criterion) {
@@ -81,6 +83,68 @@ fn histogram_record(c: &mut Criterion) {
8183
});
8284
}
8385

86+
fn histogram_record_with_non_static_values(c: &mut Criterion) {
87+
let histogram = create_histogram("Histogram_Record_With_Non_Static_Values");
88+
c.bench_function("Histogram_Record_With_Non_Static_Values", |b| {
89+
b.iter_batched(
90+
|| {
91+
(
92+
[
93+
"value1".to_owned(),
94+
"value2".to_owned(),
95+
"value3".to_owned(),
96+
"value4".to_owned(),
97+
"value5".to_owned(),
98+
"value6".to_owned(),
99+
"value7".to_owned(),
100+
"value8".to_owned(),
101+
"value9".to_owned(),
102+
"value10".to_owned(),
103+
],
104+
// 4*4*10*10 = 1600 time series.
105+
CURRENT_RNG.with(|rng| {
106+
let mut rng = rng.borrow_mut();
107+
[
108+
rng.gen_range(0..4),
109+
rng.gen_range(0..4),
110+
rng.gen_range(0..10),
111+
rng.gen_range(0..10),
112+
]
113+
}),
114+
)
115+
},
116+
|(attribute_values, rands)| {
117+
let index_first_attribute = rands[0];
118+
let index_second_attribute = rands[1];
119+
let index_third_attribute = rands[2];
120+
let index_fourth_attribute = rands[3];
121+
histogram.record(
122+
1,
123+
&[
124+
KeyValue::new(
125+
"attribute1",
126+
attribute_values[index_first_attribute].as_str().to_owned(),
127+
),
128+
KeyValue::new(
129+
"attribute2",
130+
attribute_values[index_second_attribute].as_str().to_owned(),
131+
),
132+
KeyValue::new(
133+
"attribute3",
134+
attribute_values[index_third_attribute].as_str().to_owned(),
135+
),
136+
KeyValue::new(
137+
"attribute4",
138+
attribute_values[index_fourth_attribute].as_str().to_owned(),
139+
),
140+
],
141+
);
142+
},
143+
BatchSize::SmallInput,
144+
);
145+
});
146+
}
147+
84148
#[cfg(not(target_os = "windows"))]
85149
criterion_group! {
86150
name = benches;

0 commit comments

Comments
 (0)