Skip to content

Commit 13fde82

Browse files
committed
Fix metrics counter benchmarks
1 parent 20226cd commit 13fde82

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

opentelemetry-sdk/benches/metric_counter.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ thread_local! {
3232

3333
// Run this benchmark with:
3434
// cargo bench --bench metric_counter
35-
fn create_counter() -> Counter<u64> {
35+
fn create_counter(name: &'static str) -> Counter<u64> {
3636
let meter_provider: SdkMeterProvider = SdkMeterProvider::builder()
3737
.with_reader(ManualReader::builder().build())
3838
.build();
3939
let meter = meter_provider.meter("benchmarks");
4040

41-
meter.u64_counter("counter_bench").init()
41+
meter.u64_counter(name).init()
4242
}
4343

4444
fn criterion_benchmark(c: &mut Criterion) {
@@ -51,8 +51,8 @@ fn counter_add(c: &mut Criterion) {
5151
"value10",
5252
];
5353

54-
let counter = create_counter();
5554
c.bench_function("Counter_Add_Sorted", |b| {
55+
let counter = create_counter("Counter_Add_Sorted");
5656
b.iter(|| {
5757
// 4*4*10*10 = 1600 time series.
5858
let rands = CURRENT_RNG.with(|rng| {
@@ -81,6 +81,7 @@ fn counter_add(c: &mut Criterion) {
8181
});
8282

8383
c.bench_function("Counter_Add_Unsorted", |b| {
84+
let counter = create_counter("Counter_Add_Unsorted");
8485
b.iter(|| {
8586
// 4*4*10*10 = 1600 time series.
8687
let rands = CURRENT_RNG.with(|rng| {
@@ -108,11 +109,13 @@ fn counter_add(c: &mut Criterion) {
108109
});
109110
});
110111

111-
// Cause overflow.
112-
for v in 0..2001 {
113-
counter.add(100, &[KeyValue::new("A", v.to_string())]);
114-
}
115112
c.bench_function("Counter_Overflow", |b| {
113+
let counter = create_counter("Counter_Overflow");
114+
// Cause overflow.
115+
for v in 0..2001 {
116+
counter.add(100, &[KeyValue::new("A", v.to_string())]);
117+
}
118+
116119
b.iter(|| {
117120
// 4*4*10*10 = 1600 time series.
118121
let rands = CURRENT_RNG.with(|rng| {

0 commit comments

Comments
 (0)