Skip to content

Commit ab6f3f2

Browse files
committed
Metric benchmark - more isolation
1 parent 75eb96d commit ab6f3f2

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

opentelemetry-sdk/benches/metric_counter.rs

+32-28
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,25 @@ fn create_counter(name: &'static str) -> Counter<u64> {
3838
.build();
3939
let meter = meter_provider.meter("benchmarks");
4040

41-
meter.u64_counter(name).init()
41+
println!("Counter_Created");
42+
meter.u64_counter(name).init()
4243
}
4344

4445
fn criterion_benchmark(c: &mut Criterion) {
45-
counter_add(c);
46+
counter_add_sorted(c);
47+
counter_add_unsorted(c);
48+
counter_overflow(c);
4649
}
4750

48-
fn counter_add(c: &mut Criterion) {
51+
fn counter_add_sorted(c: &mut Criterion) {
4952
let attribute_values = [
5053
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
5154
"value10",
5255
];
5356

57+
let counter = create_counter("Counter_Add_Sorted");
5458
c.bench_function("Counter_Add_Sorted", |b| {
55-
let counter = create_counter("Counter_Add_Sorted");
59+
5660
b.iter(|| {
5761
// 4*4*10*10 = 1600 time series.
5862
let rands = CURRENT_RNG.with(|rng| {
@@ -79,9 +83,16 @@ fn counter_add(c: &mut Criterion) {
7983
);
8084
});
8185
});
86+
}
8287

83-
c.bench_function("Counter_Add_Unsorted", |b| {
84-
let counter = create_counter("Counter_Add_Unsorted");
88+
fn counter_add_unsorted(c: &mut Criterion) {
89+
let attribute_values = [
90+
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
91+
"value10",
92+
];
93+
94+
let counter = create_counter("Counter_Add_Unsorted");
95+
c.bench_function("Counter_Add_Unsorted", |b| {
8596
b.iter(|| {
8697
// 4*4*10*10 = 1600 time series.
8798
let rands = CURRENT_RNG.with(|rng| {
@@ -108,14 +119,22 @@ fn counter_add(c: &mut Criterion) {
108119
);
109120
});
110121
});
122+
}
111123

112-
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-
}
124+
fn counter_overflow(c: &mut Criterion) {
125+
let attribute_values = [
126+
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
127+
"value10",
128+
];
118129

130+
let counter = create_counter("Counter_Overflow");
131+
println!("Counter_Overflow hello init");
132+
// Cause overflow.
133+
for v in 0..2001 {
134+
counter.add(100, &[KeyValue::new("A", v.to_string())]);
135+
}
136+
137+
c.bench_function("Counter_Overflow", |b| {
119138
b.iter(|| {
120139
// 4*4*10*10 = 1600 time series.
121140
let rands = CURRENT_RNG.with(|rng| {
@@ -134,29 +153,14 @@ fn counter_add(c: &mut Criterion) {
134153
counter.add(
135154
1,
136155
&[
137-
KeyValue::new("attribute1", attribute_values[index_first_attribute]),
138156
KeyValue::new("attribute2", attribute_values[index_second_attribute]),
139157
KeyValue::new("attribute3", attribute_values[index_third_attribute]),
158+
KeyValue::new("attribute1", attribute_values[index_first_attribute]),
140159
KeyValue::new("attribute4", attribute_values[index_fourth_attribute]),
141160
],
142161
);
143162
});
144163
});
145-
146-
c.bench_function("ThreadLocal_Random_Generator_5", |b| {
147-
b.iter(|| {
148-
let __i1 = CURRENT_RNG.with(|rng| {
149-
let mut rng = rng.borrow_mut();
150-
[
151-
rng.gen_range(0..4),
152-
rng.gen_range(0..4),
153-
rng.gen_range(0..10),
154-
rng.gen_range(0..10),
155-
rng.gen_range(0..10),
156-
]
157-
});
158-
});
159-
});
160164
}
161165

162166
#[cfg(not(target_os = "windows"))]

0 commit comments

Comments
 (0)