62 lines
1.9 KiB
Rust
62 lines
1.9 KiB
Rust
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
fn parse_large_script(c: &mut Criterion) {
|
|
let script_path = Path::new("/tmp/bench_large.sh");
|
|
|
|
let script_content = fs::read_to_string(script_path)
|
|
.expect("Failed to read benchmark script. Run `python3 benches/generate.py` first.");
|
|
|
|
let byte_size = script_content.len();
|
|
let line_count = script_content.lines().count();
|
|
|
|
println!("Benchmark file: {} lines, {} bytes", line_count, byte_size);
|
|
|
|
c.bench_function("parse_script_large", |b| {
|
|
b.iter(|| {
|
|
let result =
|
|
workshop_baker::bake::parser::parse_script(black_box(&script_content.clone()));
|
|
black_box(result)
|
|
});
|
|
});
|
|
}
|
|
|
|
fn parse_medium_script(c: &mut Criterion) {
|
|
let script_path = Path::new("/tmp/bench_medium.sh");
|
|
|
|
let script_content = fs::read_to_string(script_path)
|
|
.expect("Failed to read benchmark script. Run `python3 benches/generate.py` first.");
|
|
|
|
c.bench_function("parse_script_medium", |b| {
|
|
b.iter(|| {
|
|
let result =
|
|
workshop_baker::bake::parser::parse_script(black_box(&script_content.clone()));
|
|
black_box(result)
|
|
});
|
|
});
|
|
}
|
|
|
|
fn parse_small_script(c: &mut Criterion) {
|
|
let script_path = Path::new("/tmp/bench_small.sh");
|
|
|
|
let script_content = fs::read_to_string(script_path)
|
|
.expect("Failed to read benchmark script. Run `python3 benches/generate.py` first.");
|
|
|
|
c.bench_function("parse_script_small", |b| {
|
|
b.iter(|| {
|
|
let result =
|
|
workshop_baker::bake::parser::parse_script(black_box(&script_content.clone()));
|
|
black_box(result)
|
|
});
|
|
});
|
|
}
|
|
|
|
criterion_group!(
|
|
benches,
|
|
parse_small_script,
|
|
parse_medium_script,
|
|
parse_large_script
|
|
);
|
|
criterion_main!(benches);
|