#![allow(missing_docs)]
use criterion::{Criterion, criterion_group, criterion_main};
use serde_json::json;
use std::hint::black_box;
use veerdiff::align::align;
use veerdiff::config::Config;
use veerdiff::model::{Step, StepKind, Trace};
fn synthetic(n: usize, salt: &str) -> Trace {
let mut steps = Vec::with_capacity(n);
for i in 0..n {
if i % 2 == 0 {
steps.push(
Step::new(StepKind::Message)
.with_role("assistant")
.with_content(format!("step {i} reasoning about the {salt} task")),
);
} else {
steps.push(
Step::new(StepKind::ToolCall)
.with_name("do_work")
.with_args(json!({ "index": i, "mode": salt })),
);
}
}
Trace::from_steps(steps)
}
fn bench_align(c: &mut Criterion) {
let cfg = Config::default();
let mut group = c.benchmark_group("align");
for &n in &[50usize, 200, 500] {
let a = synthetic(n, "alpha");
let mut b = synthetic(n, "alpha");
for step in b.steps.iter_mut().skip(n / 2) {
if let Some(c) = &mut step.content {
c.push_str(" (changed)");
}
}
group.bench_function(format!("n={n}"), |bencher| {
bencher.iter(|| align(black_box(&a), black_box(&b), black_box(&cfg)));
});
}
group.finish();
}
criterion_group!(benches, bench_align);
criterion_main!(benches);