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

Use static dispatch to validate value types for public APIs #1716

Closed
Closed
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
29 changes: 29 additions & 0 deletions opentelemetry/benches/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ fn attributes_creation(c: &mut Criterion) {
});
});

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

#[allow(clippy::useless_vec)]
c.bench_function("ProvideMultipleKeyValuesUsingGenericMethod", |b| {
b.iter(|| {
let _v1 = black_box(vec![
no_op("attribute1", "value1"),
no_op("attribute2", "value2"),
no_op("attribute3", "value3"),
no_op("attribute4", "value4"),
]);
});
});

#[allow(clippy::useless_vec)]
c.bench_function("CreateOtelKeyValueVector", |b| {
b.iter(|| {
Expand All @@ -65,6 +83,17 @@ fn attributes_creation(c: &mut Criterion) {
});
}


trait OTelValueType {}

impl OTelValueType for u32 {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can implement this trait for all the OpenTelemetry supported types.


impl OTelValueType for &str {}

fn no_op<T : OTelValueType>(key: &'static str, value: T) {
black_box("test");
}

criterion_group!(benches, criterion_benchmark);

criterion_main!(benches);
Loading