Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metric benchmarks #1907

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 50 additions & 11 deletions opentelemetry/benches/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
use criterion::{criterion_group, criterion_main, Criterion};
/*
Benchmark Results:
criterion = "0.5.1"
OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
RAM: 64.0 GB
| Test | Average time|
|-----------------------------------------------------|-------------|
| NoAttributes | 1.1616 ns |
| AddWithInlineStaticAttributes | 13.296 ns |
| AddWithStaticArray | 1.1612 ns |
| AddWithDynamicAttributes | 110.40 ns |
| AddWithDynamicAttributes_WithStringAllocation | 77.338 ns |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This benchmark method runs much faster when run in isolation. It takes around 80 ns instead of 110 ns.

*/

use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
use opentelemetry::{global, metrics::Counter, KeyValue};
cijothomas marked this conversation as resolved.
Show resolved Hide resolved

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

c.bench_function("Counter_NoAttributes", |b| {
c.bench_function("NoAttributes", |b| {
b.iter(|| {
counter.add(1, &[]);
});
});

c.bench_function("Counter_AddWithInlineStaticAttributes", |b| {
c.bench_function("AddWithInlineStaticAttributes", |b| {
b.iter(|| {
counter.add(
1,
Expand All @@ -44,22 +59,46 @@ fn counter_add(c: &mut Criterion) {
KeyValue::new("attribute4", "value4"),
];

c.bench_function("Counter_AddWithStaticArray", |b| {
c.bench_function("AddWithStaticArray", |b| {
b.iter(|| {
counter.add(1, &kv);
});
});

c.bench_function("Counter_AddWithDynamicAttributes", |b| {
c.bench_function("AddWithDynamicAttributes", |b| {
b.iter_batched(
|| {
let value1 = "value1".to_string();
let value2 = "value2".to_string();
let value3 = "value3".to_string();
let value4 = "value4".to_string();

(value1, value2, value3, value4)
},
|values| {
let kv = &[
KeyValue::new("attribute1", values.0),
KeyValue::new("attribute2", values.1),
KeyValue::new("attribute3", values.2),
KeyValue::new("attribute4", values.3),
];

counter.add(1, kv);
},
BatchSize::SmallInput,
);
});

c.bench_function("AddWithDynamicAttributes_WithStringAllocation", |b| {
b.iter(|| {
let kv = vec![
KeyValue::new("attribute1", "value1"),
KeyValue::new("attribute2", "value2"),
KeyValue::new("attribute3", "value3"),
KeyValue::new("attribute4", "value4"),
let kv = &[
KeyValue::new("attribute1", black_box("value1".to_string())),
KeyValue::new("attribute2", black_box("value2".to_string())),
KeyValue::new("attribute3", black_box("value3".to_string())),
KeyValue::new("attribute4", black_box("value4".to_string())),
];

counter.add(1, &kv);
counter.add(1, kv);
});
});
}
Expand Down
Loading