use criterion::{Criterion, criterion_group, criterion_main};
use std::fs;
use std::time::Instant;
fn generate_large_csv(rows: usize) -> String {
let mut csv_content = String::with_capacity(rows * 100);
csv_content.push_str("row_id,region,department,sales_amount,employee_count\n");
let regions = ["north", "south", "east", "west", "central"];
let departments = ["sales", "engineering", "marketing", "support", "hr"];
for i in 0..rows {
let region = regions[i % regions.len()];
let department = departments[i % departments.len()];
let sales_amount = 1000.0 + ((i * 31) % 49000) as f64;
let employee_count = (i % 50) + 1;
csv_content.push_str(&format!(
"row_{i},{region},{department},{sales_amount:.2},{employee_count}\n"
));
}
csv_content
}
fn benchmark_compile_time(c: &mut Criterion) {
let mut group = c.benchmark_group("csv_macro_compile_time");
let sizes = [500_000];
for &size in &sizes {
group.bench_function(format!("csv_rows_{size}"), |b| {
b.iter_custom(|iters| {
let mut total_duration = std::time::Duration::new(0, 0);
for _i in 0..iters {
let csv_content = generate_large_csv(size);
fs::write("benchmark_data.csv", &csv_content).unwrap();
let start = Instant::now();
let t = trybuild::TestCases::new();
t.pass("benches/build-sample/benchmark_test.rs");
let duration = start.elapsed();
total_duration += duration;
}
let _ = fs::remove_file("benchmark_data.csv");
total_duration
});
});
}
group.finish();
}
criterion_group!(benches, benchmark_compile_time);
criterion_main!(benches);