U21: remove the three benchp1 bench examples (ec-subs, ec-ass, ec-pgs); bench lives in tools/ec-bench
Browse files at this commit9af038cc4fefdd69ee7a6688c7adb16606c304beParent: 41510f03 changed files +0 -227
- crates/ec-ass/examples/benchp1.rs +0 -44
- crates/ec-pgs/examples/benchp1.rs +0 -139
- crates/ec-subs/examples/benchp1.rs +0 -44
crates/ec-ass/examples/benchp1.rsdeleted+0 -44
| @@ -1,44 +0,0 @@ | |||
| 1 | -//! benchp1: ASS parse throughput for lanes/bench.md ("lane benchp1"). | ||
| 2 | -//! | ||
| 3 | -//! usage: benchp1 ass <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). | ||
| 8 | -use std::hint::black_box; | ||
| 9 | -use std::time::Instant; | ||
| 10 | - | ||
| 11 | -fn 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 | - "ass" => ec_ass::parse(b), | ||
| 18 | - | ||
| 19 | - _ => panic!("kind must be ass"), | ||
| 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 | -} | ||
crates/ec-pgs/examples/benchp1.rsdeleted+0 -139
| @@ -1,139 +0,0 @@ | |||
| 1 | -//! benchp1: PGS (.sup) decode throughput for lanes/bench.md ("lane benchp1"). | ||
| 2 | -//! | ||
| 3 | -//! usage: | ||
| 4 | -//! benchp1 gen <out.sup> <seconds> write a synthetic .sup: every second one display set | ||
| 5 | -//! shows a 64x32 object, 0.8 s later a clear set follows | ||
| 6 | -//! (2 display sets per second, 90 kHz pts). | ||
| 7 | -//! benchp1 decode <file.sup> [reps] decode the whole file `reps` times (default 5) with a | ||
| 8 | -//! fresh decoder each time; print the best time, MB/s, the | ||
| 9 | -//! rendered frame count and the stream duration from the pts. | ||
| 10 | -//! | ||
| 11 | -//! The generator uses the same segment layout as the crate's tests (`tests/fuzz_regressions.rs`). | ||
| 12 | -//! ffmpeg has no PGS encoder, so this is the input source for the row. | ||
| 13 | -use std::hint::black_box; | ||
| 14 | -use std::time::Instant; | ||
| 15 | - | ||
| 16 | -use ec_pgs::{PgsDecoder, SEG_END, SEG_ODS, SEG_PCS, SEG_PDS}; | ||
| 17 | - | ||
| 18 | -fn segment(pts: u32, kind: u8, body: &[u8]) -> Vec<u8> { | ||
| 19 | - let mut out = b"PG".to_vec(); | ||
| 20 | - out.extend_from_slice(&pts.to_be_bytes()); | ||
| 21 | - out.extend_from_slice(&pts.to_be_bytes()); | ||
| 22 | - out.push(kind); | ||
| 23 | - out.extend_from_slice(&(body.len() as u16).to_be_bytes()); | ||
| 24 | - out.extend_from_slice(body); | ||
| 25 | - out | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -/// A 1920x1080 epoch-start composition with `objects` placed objects (0 or 1). | ||
| 29 | -fn pcs(pts: u32, x: u16, y: u16, objects: u8) -> Vec<u8> { | ||
| 30 | - let mut body = vec![0x07, 0x80, 0x04, 0x38, 0x10, 0, 0, 0x80, 0, 0, objects]; | ||
| 31 | - if objects == 1 { | ||
| 32 | - body.extend_from_slice(&[0, 0, 0, 0]); | ||
| 33 | - body.extend_from_slice(&x.to_be_bytes()); | ||
| 34 | - body.extend_from_slice(&y.to_be_bytes()); | ||
| 35 | - } | ||
| 36 | - segment(pts, SEG_PCS, &body) | ||
| 37 | -} | ||
| 38 | - | ||
| 39 | -/// Palette entry 1 opaque white. | ||
| 40 | -fn pds(pts: u32) -> Vec<u8> { | ||
| 41 | - segment(pts, SEG_PDS, &[0, 0, 1, 235, 128, 128, 255]) | ||
| 42 | -} | ||
| 43 | - | ||
| 44 | -/// One 64x32 object, RLE: each row is 64 pixels of colour 1 then an end-of-line code. | ||
| 45 | -fn ods(pts: u32) -> Vec<u8> { | ||
| 46 | - let (w, h) = (64u16, 32u16); | ||
| 47 | - let mut rle = Vec::new(); | ||
| 48 | - for _ in 0..h { | ||
| 49 | - rle.extend(std::iter::repeat_n(1u8, w as usize)); | ||
| 50 | - rle.extend_from_slice(&[0, 0]); | ||
| 51 | - } | ||
| 52 | - let mut body = vec![0, 0, 0, 0xC0]; | ||
| 53 | - body.extend_from_slice(&((rle.len() + 4) as u32).to_be_bytes()[1..]); | ||
| 54 | - body.extend_from_slice(&w.to_be_bytes()); | ||
| 55 | - body.extend_from_slice(&h.to_be_bytes()); | ||
| 56 | - body.extend_from_slice(&rle); | ||
| 57 | - segment(pts, SEG_ODS, &body) | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -fn generate(path: &str, seconds: u32) { | ||
| 61 | - let mut out = Vec::new(); | ||
| 62 | - for s in 0..seconds { | ||
| 63 | - let t = s * 90_000; | ||
| 64 | - let x = ((s * 37) % 1800) as u16; | ||
| 65 | - let y = ((s * 19) % 1000) as u16; | ||
| 66 | - out.extend(pcs(t, x, y, 1)); | ||
| 67 | - out.extend(pds(t)); | ||
| 68 | - out.extend(ods(t)); | ||
| 69 | - out.extend(segment(t, SEG_END, &[])); | ||
| 70 | - let c = t + 72_000; | ||
| 71 | - out.extend(pcs(c, 0, 0, 0)); | ||
| 72 | - out.extend(segment(c, SEG_END, &[])); | ||
| 73 | - } | ||
| 74 | - std::fs::write(path, &out).expect("write sup"); | ||
| 75 | - println!("wrote {path} bytes={} display_sets={}", out.len(), 2 * seconds); | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -/// (segment count, the last segment's pts in seconds), walking the segment headers. | ||
| 79 | -fn scan(bytes: &[u8]) -> (usize, f64) { | ||
| 80 | - let mut pos = 0; | ||
| 81 | - let mut last = 0u32; | ||
| 82 | - let mut segments = 0; | ||
| 83 | - while pos + 13 <= bytes.len() { | ||
| 84 | - last = u32::from_be_bytes(bytes[pos + 2..pos + 6].try_into().unwrap()); | ||
| 85 | - let size = u16::from_be_bytes([bytes[pos + 11], bytes[pos + 12]]) as usize; | ||
| 86 | - pos += 13 + size; | ||
| 87 | - segments += 1; | ||
| 88 | - } | ||
| 89 | - (segments, f64::from(last) / 90_000.0) | ||
| 90 | -} | ||
| 91 | - | ||
| 92 | -/// One full decode with a fresh decoder: (rendered frames, push errors). The file is fed one | ||
| 93 | -/// segment at a time and the finished frames are dropped after each push, as a streaming reader | ||
| 94 | -/// would. A full 1920x1080 canvas is about 8 MB, so draining per segment keeps the decoder's | ||
| 95 | -/// output queue at most one frame deep. | ||
| 96 | -fn decode_once(bytes: &[u8]) -> (usize, usize) { | ||
| 97 | - let mut d = PgsDecoder::new(); | ||
| 98 | - let (mut frames, mut errors) = (0, 0); | ||
| 99 | - let mut pos = 0; | ||
| 100 | - while pos + 13 <= bytes.len() { | ||
| 101 | - let size = u16::from_be_bytes([bytes[pos + 11], bytes[pos + 12]]) as usize; | ||
| 102 | - let end = (pos + 13 + size).min(bytes.len()); | ||
| 103 | - if d.push(black_box(&bytes[pos..end])).is_err() { | ||
| 104 | - errors += 1; | ||
| 105 | - } | ||
| 106 | - pos = end; | ||
| 107 | - while let Some(f) = d.take_frame() { | ||
| 108 | - frames += 1; | ||
| 109 | - black_box(f); | ||
| 110 | - } | ||
| 111 | - } | ||
| 112 | - (frames, errors) | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -fn decode(path: &str, reps: usize) { | ||
| 116 | - let bytes = std::fs::read(path).expect("read sup"); | ||
| 117 | - let (frames, errors) = decode_once(&bytes); | ||
| 118 | - let mut best = f64::MAX; | ||
| 119 | - for _ in 0..reps { | ||
| 120 | - let t = Instant::now(); | ||
| 121 | - black_box(decode_once(black_box(&bytes))); | ||
| 122 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 123 | - } | ||
| 124 | - let (segments, dur) = scan(&bytes); | ||
| 125 | - println!( | ||
| 126 | - "bytes={} segments={segments} frames={frames} push_errors={errors} duration_s={dur:.1} best_decode_s={best:.4} mb_s={:.2} reps={reps}", | ||
| 127 | - bytes.len(), | ||
| 128 | - bytes.len() as f64 / best / 1e6 | ||
| 129 | - ); | ||
| 130 | -} | ||
| 131 | - | ||
| 132 | -fn main() { | ||
| 133 | - let args: Vec<String> = std::env::args().collect(); | ||
| 134 | - match args.get(1).map(String::as_str) { | ||
| 135 | - Some("gen") => generate(&args[2], args[3].parse().expect("seconds")), | ||
| 136 | - Some("decode") => decode(&args[2], args.get(3).map_or(5, |s| s.parse().expect("reps"))), | ||
| 137 | - _ => panic!("usage: benchp1 gen <out.sup> <seconds> | decode <file.sup> [reps]"), | ||
| 138 | - } | ||
| 139 | -} | ||
crates/ec-subs/examples/benchp1.rsdeleted+0 -44
| @@ -1,44 +0,0 @@ | |||
| 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). | ||
| 8 | -use std::hint::black_box; | ||
| 9 | -use std::time::Instant; | ||
| 10 | - | ||
| 11 | -fn 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 | -} | ||