Skip to main content

bench/
bench.rs

1//! Two-track bench helper: `bench <file.rst> <iters>`.
2//!
3//! Runs `publish_string_with` (report_level 1, matching the Python side of
4//! `benches/two_track.py`) `iters` times and prints `elapsed_ms` plus the
5//! output length (to prove the work wasn't optimized away).
6
7use docutils_core::core::publish_string_with;
8use docutils_core::settings::Settings;
9
10fn main() {
11    let path = std::env::args().nth(1).expect("usage: bench <file.rst> <iters>");
12    let iters: usize = std::env::args()
13        .nth(2)
14        .expect("usage: bench <file.rst> <iters>")
15        .parse()
16        .expect("iters must be a number");
17    let source = std::fs::read_to_string(&path).expect("read input");
18    let settings = Settings {
19        report_level: 1,
20        ..Settings::default()
21    };
22    // Warm-up (allocator, first-parse caches) outside the clock.
23    let (first, _) = publish_string_with(&source, &settings, None).expect("bench parse");
24    let start = std::time::Instant::now();
25    let mut len = 0;
26    for _ in 0..iters {
27        let (html, _) = publish_string_with(&source, &settings, None).expect("bench parse");
28        len = html.len();
29    }
30    let ms = start.elapsed().as_secs_f64() * 1000.0;
31    println!("iters={iters} elapsed_ms={ms:.1} html_len={len} first_len={}", first.len());
32}