forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

benchp1.rs44 lines, 1.7 KiBHistoryRawDownload
1//! benchp1: SubRip and WebVTT parse throughput for lanes/bench.md ("lane benchp1").
2//!
3//! usage: benchp1 <srt|vtt> <file> [reps]
4//!
5//! Parses the whole file `reps` times (default 5). Each timed run repeats the parse until it
6//! takes at least 0.2 s, so the per-parse time is not timer noise. Prints the best per-parse
7//! time, the throughput in MB/s and the cue count of the parsed track (checked against ffprobe).
8use std::hint::black_box;
9use std::time::Instant;
10
11fn main() {
12 let args: Vec<String> = std::env::args().collect();
13 let kind = args.get(1).map(String::as_str).unwrap_or("");
14 let bytes = std::fs::read(&args[2]).expect("read subtitle file");
15 let reps: usize = args.get(3).map_or(5, |s| s.parse().expect("reps"));
16 let parse = |b: &[u8]| match kind {
17 "srt" => ec_subs::srt::parse(b),
18 "vtt" => ec_subs::webvtt::parse(b),
19 _ => panic!("kind must be srt or vtt"),
20 };
21
22 let first = parse(&bytes).expect("parse");
23 let cues = first.cues.len();
24 let skipped = first.skipped;
25 let t0 = Instant::now();
26 black_box(parse(black_box(&bytes)).expect("parse"));
27 let one = t0.elapsed().as_secs_f64().max(1e-6);
28 let inner = ((0.2 / one).ceil() as usize).max(1);
29
30 let mut best = f64::MAX;
31 for _ in 0..reps {
32 let t = Instant::now();
33 for _ in 0..inner {
34 black_box(parse(black_box(&bytes)).expect("parse"));
35 }
36 best = best.min(t.elapsed().as_secs_f64() / inner as f64);
37 }
38 let mb_s = bytes.len() as f64 / best / 1e6;
39 println!(
40 "kind={kind} bytes={} cues={cues} skipped={skipped} best_parse_ms={:.3} mb_s={mb_s:.2} reps={reps} inner={inner}",
41 bytes.len(),
42 best * 1e3
43 );
44}