From 1123738e3ed8365b7b132501211f9947477bb361 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Mon, 6 May 2024 17:29:36 -0700 Subject: [PATCH 1/3] Use static dispatch --- opentelemetry/benches/attributes.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/opentelemetry/benches/attributes.rs b/opentelemetry/benches/attributes.rs index 081af06c36..e6743cc942 100644 --- a/opentelemetry/benches/attributes.rs +++ b/opentelemetry/benches/attributes.rs @@ -40,6 +40,12 @@ fn attributes_creation(c: &mut Criterion) { }); }); + c.bench_function("CreateTupleKeyValueUsingGenerics", |b| { + b.iter(|| { + let _v1 = black_box(no_op("attribute1", "value1")); + }); + }); + #[allow(clippy::useless_vec)] c.bench_function("CreateOtelKeyValueVector", |b| { b.iter(|| { @@ -65,6 +71,17 @@ fn attributes_creation(c: &mut Criterion) { }); } + +trait OTelValueType {} + +impl OTelValueType for u32 {} + +impl OTelValueType for &str {} + +fn no_op(key: &'static str, value: T) { + black_box("test"); +} + criterion_group!(benches, criterion_benchmark); criterion_main!(benches); From 21cdb50e271d3a9d3a6c2e0b34ef6eb02be0bfdd Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Mon, 6 May 2024 17:48:22 -0700 Subject: [PATCH 2/3] Code changes --- opentelemetry/benches/attributes.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/opentelemetry/benches/attributes.rs b/opentelemetry/benches/attributes.rs index e6743cc942..8cf48485ae 100644 --- a/opentelemetry/benches/attributes.rs +++ b/opentelemetry/benches/attributes.rs @@ -40,12 +40,24 @@ fn attributes_creation(c: &mut Criterion) { }); }); - c.bench_function("CreateTupleKeyValueUsingGenerics", |b| { + c.bench_function("CreateKeyValueUsingGenericMethod", |b| { b.iter(|| { let _v1 = black_box(no_op("attribute1", "value1")); }); }); + #[allow(clippy::useless_vec)] + c.bench_function("CreateKeyValueVectorUsingGenericMethod", |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(|| { From 59e3d051254d686b28d7104660b6654720ccf264 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai Date: Mon, 6 May 2024 17:50:48 -0700 Subject: [PATCH 3/3] Rename benchmark methods --- opentelemetry/benches/attributes.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opentelemetry/benches/attributes.rs b/opentelemetry/benches/attributes.rs index 8cf48485ae..42492f70cc 100644 --- a/opentelemetry/benches/attributes.rs +++ b/opentelemetry/benches/attributes.rs @@ -40,14 +40,14 @@ fn attributes_creation(c: &mut Criterion) { }); }); - c.bench_function("CreateKeyValueUsingGenericMethod", |b| { + c.bench_function("ProvideKeyValueUsingGenericMethod", |b| { b.iter(|| { let _v1 = black_box(no_op("attribute1", "value1")); }); }); #[allow(clippy::useless_vec)] - c.bench_function("CreateKeyValueVectorUsingGenericMethod", |b| { + c.bench_function("ProvideMultipleKeyValuesUsingGenericMethod", |b| { b.iter(|| { let _v1 = black_box(vec![ no_op("attribute1", "value1"),