forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

perf.rs63 lines, 2.1 KiBHistoryRawDownload
1//! Throughput floor: SD >= 300 fps, HD >= 60 fps (release builds only).
2mod common;
3
4use std::time::Instant;
5
6use common::*;
7use ec_dv::DvVideoDecoder;
8
9fn fps(f: &Flavour) -> Option<f64> {
10 let path = make(f, "perf", "dv", true, 10)?;
11 let data = std::fs::read(path).unwrap();
12 let fs = ec_dv::frame_profile(None, &data).unwrap().frame_size;
13 let frames: Vec<&[u8]> = data.chunks_exact(fs).collect();
14 let mut d = DvVideoDecoder::new();
15 d.decode(frames[0]).unwrap();
16 let start = Instant::now();
17 let mut n = 0u32;
18 while start.elapsed().as_secs_f64() < 1.0 || n < 20 {
19 for fr in &frames {
20 std::hint::black_box(d.decode(fr).unwrap());
21 n += 1;
22 }
23 }
24 Some(f64::from(n) / start.elapsed().as_secs_f64())
25}
26
27/// A shared machine under load cannot show the floor: the check is skipped (and says so) when the
28/// 1-minute load average exceeds half the cores, which is how the lane servers look while other
29/// jobs run. An idle machine enforces the floor.
30fn machine_is_busy() -> bool {
31 let load = std::fs::read_to_string("/proc/loadavg")
32 .ok()
33 .and_then(|s| s.split_whitespace().next().and_then(|v| v.parse::<f64>().ok()));
34 let cores = std::thread::available_parallelism().map_or(1, |n| n.get()) as f64;
35 load.is_some_and(|l| l > cores * 0.5)
36}
37
38#[test]
39fn decode_speed() {
40 if !ffmpeg_or_skip() {
41 return;
42 }
43 let mut bad = Vec::new();
44 for f in FLAVOURS {
45 let hd = f.size.starts_with("1440") || f.size.starts_with("1280") || f.size.starts_with("960");
46 let mut r = 0f64;
47 for _ in 0..3 {
48 let Some(x) = fps(f) else { panic!("fixture {}", f.name) };
49 r = r.max(x);
50 if r >= if hd { 60.0 } else { 300.0 } {
51 break;
52 }
53 }
54 eprintln!("{}: {r:.0} fps", f.name);
55 if !cfg!(debug_assertions) && !machine_is_busy() {
56 let floor = if hd { 60.0 } else { 300.0 };
57 if r < floor {
58 bad.push(format!("{}: {r:.0} fps < {floor}", f.name));
59 }
60 }
61 }
62 assert!(bad.is_empty(), "{bad:?}");
63}