From 28ef1086c3779d78cb70bcd1aeac054a3fc61217 Mon Sep 17 00:00:00 2001 From: Utkarsh Umesan Pillai <66651184+utpilla@users.noreply.github.com> Date: Wed, 4 Sep 2024 19:33:20 +0000 Subject: [PATCH] Add benchmarks --- opentelemetry/benches/attributes.rs | 44 +++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/opentelemetry/benches/attributes.rs b/opentelemetry/benches/attributes.rs index 5e1217b622..14eff1af2d 100644 --- a/opentelemetry/benches/attributes.rs +++ b/opentelemetry/benches/attributes.rs @@ -1,15 +1,17 @@ /* 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| -|--------------------------------|-------------| -| CreateOTelKey_Static | 1.2 ns | -| CreateOTelKey_Owned | 12.6 ns | -| CreateOTelKey_Arc | 23.35 ns | -| CreateOTelKeyValue | 3.24 ns | -| CreateTupleKeyValue | 671 ps | -| CreateOtelKeyValueArray | 18.4 ns | -| CreateTupleKeyValueArray | 2.73 ns | +| Test | Average time| +|--------------------------------------------------|-------------| +| CreateOTelKey_Static | 1.2 ns | +| CreateOTelKey_Owned | 12.6 ns | +| CreateOTelKey_Arc | 23.35 ns | +| CreateOTelKeyValue | 3.24 ns | +| CreateTupleKeyValue | 671 ps | +| CreateOtelKeyValueArray | 18.4 ns | +| CreateOtelKeyValueArrayWithMixedValueTypes | 18.1 ns | +| CreateOtelKeyValueArrayWithNonStaticValues | 90.1 ns | +| CreateTupleKeyValueArray | 2.73 ns | */ use criterion::{black_box, criterion_group, criterion_main, Criterion}; @@ -65,6 +67,30 @@ fn attributes_creation(c: &mut Criterion) { }); }); + c.bench_function("CreateOtelKeyValueArrayWithMixedValueTypes", |b| { + b.iter(|| { + let _v1 = black_box([ + KeyValue::new("attribute1", true), + KeyValue::new("attribute2", 100), + KeyValue::new("attribute3", 100.5), + KeyValue::new("attribute4", "value"), + ]); + }); + }); + + let value = "value1value2value3value4".to_owned(); + + c.bench_function("CreateOtelKeyValueArrayWithNonStaticValues", |b| { + b.iter(|| { + let _v1 = black_box([ + KeyValue::new("attribute1", value[0..6].to_owned()), // value[0..6] = "value1" + KeyValue::new("attribute2", value[6..12].to_owned()), // value[6..12] = "value2" + KeyValue::new("attribute3", value[12..18].to_owned()), // value[12..18] = "value3" + KeyValue::new("attribute4", value[18..24].to_owned()), // value[18..24] = "value4" + ]); + }); + }); + c.bench_function("CreateTupleKeyValueArray", |b| { b.iter(|| { let _v1 = black_box([