use criterion::{criterion_group, criterion_main, Criterion};
use std::io::Write;
fn make_large_python_file() -> String {
let mut out = String::with_capacity(500_000);
for i in 0..500 {
out.push_str(&format!("def untyped_{i}(x, y):\n return x + y\n\n"));
out.push_str(&format!(
"def typed_{i}(x: int, y: int) -> int:\n return x + y\n\n"
));
if i % 20 == 0 {
out.push_str(&format!("def view_{i}(request):\n return None\n\n"));
}
}
out
}
fn bench_scan_10k_lines(c: &mut Criterion) {
let python_src = make_large_python_file();
assert!(
python_src.lines().count() >= 9_000,
"generated file too small: {} lines",
python_src.lines().count()
);
let dir = tempfile::tempdir().unwrap();
let py_path = dir.path().join("large.py");
{
let mut f = std::fs::File::create(&py_path).unwrap();
f.write_all(python_src.as_bytes()).unwrap();
}
let path_str = py_path.to_str().unwrap().to_string();
c.bench_function("scan_10k_py_python-missing-typing", |b| {
b.iter(|| {
let findings =
ai_refactor_cli::scanner::scan_path(&path_str, Some("python-missing-typing"))
.unwrap();
criterion::black_box(findings);
});
});
c.bench_function("scan_10k_py_django-fbv", |b| {
b.iter(|| {
let findings =
ai_refactor_cli::scanner::scan_path(&path_str, Some("django-fbv")).unwrap();
criterion::black_box(findings);
});
});
}
criterion_group!(benches, bench_scan_10k_lines);
criterion_main!(benches);