Skip to content

Commit 96278a2

Browse files
authored
Merge branch 'main' into cijothomas/simple-span-processor
2 parents 59da6f1 + a34c5ee commit 96278a2

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed

opentelemetry/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ opentelemetry_sdk = { path = "../opentelemetry-sdk" } # for documentation tests
4545
criterion = { version = "0.3" }
4646

4747
[[bench]]
48-
name = "noop_metrics"
48+
name = "metrics"
4949
harness = false
5050
required-features = ["metrics"]
51+
52+
[[bench]]
53+
name = "attributes"
54+
harness = false

opentelemetry/benches/attributes.rs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use opentelemetry::KeyValue;
3+
4+
// Run this benchmark with:
5+
// cargo bench --bench attributes
6+
7+
fn criterion_benchmark(c: &mut Criterion) {
8+
attributes_creation(c);
9+
}
10+
11+
fn attributes_creation(c: &mut Criterion) {
12+
c.bench_function("CreateOTelKeyValue", |b| {
13+
b.iter(|| {
14+
let _v1 = black_box(KeyValue::new("attribute1", "value1"));
15+
});
16+
});
17+
18+
c.bench_function("CreateKeyValueTuple", |b| {
19+
b.iter(|| {
20+
let _v1 = black_box(("attribute1", "value1"));
21+
});
22+
});
23+
24+
#[allow(clippy::useless_vec)]
25+
c.bench_function("CreateVector_KeyValue", |b| {
26+
b.iter(|| {
27+
let _v1 = black_box(vec![
28+
KeyValue::new("attribute1", "value1"),
29+
KeyValue::new("attribute2", "value2"),
30+
KeyValue::new("attribute3", "value3"),
31+
KeyValue::new("attribute4", "value4"),
32+
]);
33+
});
34+
});
35+
36+
#[allow(clippy::useless_vec)]
37+
c.bench_function("CreateVector_StringPairs", |b| {
38+
b.iter(|| {
39+
let _v1 = black_box(vec![
40+
("attribute1", "value1"),
41+
("attribute2", "value2"),
42+
("attribute3", "value3"),
43+
("attribute4", "value4"),
44+
]);
45+
});
46+
});
47+
}
48+
49+
criterion_group!(benches, criterion_benchmark);
50+
51+
criterion_main!(benches);

opentelemetry/benches/noop_metrics.rs opentelemetry/benches/metrics.rs

+15-36
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
1+
use criterion::{criterion_group, criterion_main, Criterion};
22
use opentelemetry::{
33
metrics::{noop::NoopMeterProvider, Counter, MeterProvider as _},
44
KeyValue,
55
};
66

7+
// Run this benchmark with:
8+
// cargo bench --bench metrics --features=metrics
9+
710
fn create_counter() -> Counter<u64> {
811
let meter_provider: NoopMeterProvider = NoopMeterProvider::default();
912
let meter = meter_provider.meter("benchmarks");
@@ -12,21 +15,21 @@ fn create_counter() -> Counter<u64> {
1215
}
1316

1417
fn criterion_benchmark(c: &mut Criterion) {
15-
noop_counter_add(c);
18+
counter_add(c);
1619
}
1720

18-
fn noop_counter_add(c: &mut Criterion) {
19-
let noop_counter = create_counter();
21+
fn counter_add(c: &mut Criterion) {
22+
let counter = create_counter();
2023

21-
c.bench_function("NoopCounter_NoAttributes", |b| {
24+
c.bench_function("Counter_NoAttributes", |b| {
2225
b.iter(|| {
23-
noop_counter.add(1, &[]);
26+
counter.add(1, &[]);
2427
});
2528
});
2629

27-
c.bench_function("NoopCounter_AddWithInlineStaticAttributes", |b| {
30+
c.bench_function("Counter_AddWithInlineStaticAttributes", |b| {
2831
b.iter(|| {
29-
noop_counter.add(
32+
counter.add(
3033
1,
3134
&[
3235
KeyValue::new("attribute1", "value1"),
@@ -38,7 +41,7 @@ fn noop_counter_add(c: &mut Criterion) {
3841
});
3942
});
4043

41-
c.bench_function("NoopCounter_AddWithStaticArray", |b| {
44+
c.bench_function("Counter_AddWithStaticArray", |b| {
4245
b.iter(|| {
4346
let kv = [
4447
KeyValue::new("attribute1", "value1"),
@@ -47,11 +50,11 @@ fn noop_counter_add(c: &mut Criterion) {
4750
KeyValue::new("attribute4", "value4"),
4851
];
4952

50-
noop_counter.add(1, &kv);
53+
counter.add(1, &kv);
5154
});
5255
});
5356

54-
c.bench_function("NoopCounter_AddWithDynamicAttributes", |b| {
57+
c.bench_function("Counter_AddWithDynamicAttributes", |b| {
5558
b.iter(|| {
5659
let kv = vec![
5760
KeyValue::new("attribute1", "value1"),
@@ -60,31 +63,7 @@ fn noop_counter_add(c: &mut Criterion) {
6063
KeyValue::new("attribute4", "value4"),
6164
];
6265

63-
noop_counter.add(1, &kv);
64-
});
65-
});
66-
67-
#[allow(clippy::useless_vec)]
68-
c.bench_function("CreateVector_KeyValue", |b| {
69-
b.iter(|| {
70-
let _v1 = black_box(vec![
71-
KeyValue::new("attribute1", "value1"),
72-
KeyValue::new("attribute2", "value2"),
73-
KeyValue::new("attribute3", "value3"),
74-
KeyValue::new("attribute4", "value4"),
75-
]);
76-
});
77-
});
78-
79-
#[allow(clippy::useless_vec)]
80-
c.bench_function("CreateDynamicVector_StringPair", |b| {
81-
b.iter(|| {
82-
let _v1 = black_box(vec![
83-
("attribute1", "value1"),
84-
("attribute2", "value2"),
85-
("attribute3", "value3"),
86-
("attribute4", "value4"),
87-
]);
66+
counter.add(1, &kv);
8867
});
8968
});
9069
}

0 commit comments

Comments
 (0)