veerdiff 0.1.0

Semantic diff engine for LLM and agent execution traces — find exactly where two runs veer apart.
Documentation
//! Benchmarks for the alignment core.
//!
//! Alignment is `O(n·m)` in the number of steps; these benchmarks track the
//! constant factor and guard against regressions as the cost model evolves.
#![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};

/// Build a synthetic trace of `n` alternating message / tool-call steps.
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");
        // `b` diverges from `a` partway through, forcing real edit work.
        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);