Skip to content

Commit

Permalink
Add macro benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
VianneyRuhlmann committed Jul 4, 2024
1 parent ab18944 commit 32e23d9
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 57 deletions.
2 changes: 1 addition & 1 deletion trace-normalization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ duplicate = "0.4.1"
criterion = "0.5"

[[bench]]
name = "normalization_utils"
name = "normalization"
harness = false
125 changes: 125 additions & 0 deletions trace-normalization/benches/normalization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
use datadog_trace_protobuf::pb;
use std::collections::HashMap;

fn normalize_service_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("normalization/normalize_service");
let cases = &[
"",
"test_ASCII",
"Test Conversion 0f Weird !@#$%^&**() Characters",
"Data🐨dog🐶 繋がっ⛰てて",
"A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000",
];

for case in cases {
group.bench_with_input(
BenchmarkId::new(
"normalize_service",
if case.is_empty() {
"[empty string]"
} else {
case
},
),
*case,
|b, case| {
b.iter_batched_ref(
|| case.to_owned(),
datadog_trace_normalization::normalize_utils::normalize_service,
BatchSize::NumBatches(100000),
)
},
);
}
group.finish()
}

fn normalize_name_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("normalization/normalize_name");
let cases = &[
"good",
"bad-name",
"Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.Too-Long-.",
];
for case in cases {
group.bench_with_input(
BenchmarkId::new("normalize_name", case),
*case,
|b, case| {
b.iter_batched_ref(
|| case.to_owned(),
datadog_trace_normalization::normalize_utils::normalize_name,
BatchSize::NumIterations(100000),
)
},
);
}
group.finish()
}

fn normalize_span_bench(c: &mut Criterion) {
let trace = [
pb::Span {
duration: 10000000,
error: 0,
resource: "GET /some/raclette".to_string(),
service: "django".to_string(),
name: "django.controller".to_string(),
span_id: 1388,
start: 1448466874000000000,
trace_id: 424242,
meta: HashMap::from([
("user".to_string(), "leo".to_string()),
("pool".to_string(), "fondue".to_string()),
]),
metrics: HashMap::from([("cheese_weight".to_string(), 100000.0)]),
parent_id: 1111,
r#type: "http".to_string(),
meta_struct: HashMap::new(),
span_links: vec![],
},
pb::Span {
duration: 12000000,
error: 1,
resource: "GET /some/reblochon".to_string(),
service: "".to_string(),
name: "django.controller".to_string(),
span_id: 1456,
start: 1448466849000000000,
trace_id: 424242,
meta: HashMap::from([
("user".to_string(), "leo".to_string()),
("pool".to_string(), "tartiflette".to_string()),
]),
metrics: HashMap::from([("cheese_weight".to_string(), 100000.0)]),
parent_id: 1123,
r#type: "http".to_string(),
meta_struct: HashMap::new(),
span_links: vec![],
},
];

c.bench_with_input(
BenchmarkId::new("normalization/normalize_trace", "test_trace"),
&trace,
|b, case| {
b.iter_batched_ref(
|| case.to_owned(),
|s| datadog_trace_normalization::normalizer::normalize_trace(s),
BatchSize::SmallInput,
)
},
);
}

criterion_group!(
benches,
normalize_service_bench,
normalize_name_bench,
normalize_span_bench
);
criterion_main!(benches);
56 changes: 0 additions & 56 deletions trace-normalization/benches/normalization_utils.rs

This file was deleted.

0 comments on commit 32e23d9

Please sign in to comment.