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

More nit fixes to opentelemetry benches #1617

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 23 additions & 4 deletions opentelemetry/benches/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::Arc;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use opentelemetry::KeyValue;
use opentelemetry::{Key, KeyValue};

// Run this benchmark with:
// cargo bench --bench attributes
Expand All @@ -9,20 +10,38 @@ fn criterion_benchmark(c: &mut Criterion) {
}

fn attributes_creation(c: &mut Criterion) {
c.bench_function("CreateOTelKey_Static", |b| {
b.iter(|| {
let _v1 = black_box(Key::new("attribute1"));
});
});

c.bench_function("CreateOTelKey_Owned", |b| {
b.iter(|| {
let _v1 = black_box(Key::new(String::from("attribute1")));
});
});

c.bench_function("CreateOTelKey_Arc", |b| {
b.iter(|| {
let _v1 = black_box(Key::new(Arc::from("attribute1")));
});
});

c.bench_function("CreateOTelKeyValue", |b| {
b.iter(|| {
let _v1 = black_box(KeyValue::new("attribute1", "value1"));
});
});

c.bench_function("CreateKeyValueTuple", |b| {
c.bench_function("CreateTupleKeyValue", |b| {
b.iter(|| {
let _v1 = black_box(("attribute1", "value1"));
});
});

#[allow(clippy::useless_vec)]
c.bench_function("CreateVector_KeyValue", |b| {
c.bench_function("CreateOtelKeyValueVector", |b| {
b.iter(|| {
let _v1 = black_box(vec![
KeyValue::new("attribute1", "value1"),
Expand All @@ -34,7 +53,7 @@ fn attributes_creation(c: &mut Criterion) {
});

#[allow(clippy::useless_vec)]
c.bench_function("CreateVector_StringPairs", |b| {
c.bench_function("CreateTupleKeyValueVector", |b| {
b.iter(|| {
let _v1 = black_box(vec![
("attribute1", "value1"),
Expand Down
8 changes: 2 additions & 6 deletions opentelemetry/benches/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
use criterion::{criterion_group, criterion_main, Criterion};
use opentelemetry::{
metrics::{noop::NoopMeterProvider, Counter, MeterProvider as _},
KeyValue,
};
use opentelemetry::{global, metrics::Counter, KeyValue};

// Run this benchmark with:
// cargo bench --bench metrics --features=metrics

fn create_counter() -> Counter<u64> {
let meter_provider: NoopMeterProvider = NoopMeterProvider::default();
let meter = meter_provider.meter("benchmarks");
let meter = global::meter("benchmarks");
let counter = meter.u64_counter("counter_bench").init();
counter
}
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry/src/global/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@
//! pub fn my_traced_library_function() {
//! // End users of your library will configure their global meter provider
//! // so you can use the global meter without any setup
//! let tracer = global::meter("my-library-name");
//! let counter = tracer.u64_counter("my_counter").init();
//! let meter = global::meter("my-library-name");
//! let counter = meter.u64_counter("my_counter").init();
//!
//! // record metrics
//! counter.add(1, &[KeyValue::new("mykey", "myvalue")]);
Expand Down
Loading