U18: delete bench and debug examples in the container crates (dead tooling, benches live in ec-bench)
Browse files at this commitca690277c3a09f571a0df812859d65cdc6381c88Parent: 41510f08 changed files +0 -475
- crates/ec-matroska/examples/bench.rs +0 -87
- crates/ec-mp4/examples/bench.rs +0 -119
- crates/ec-mpegts/examples/bench.rs +0 -45
- crates/ec-mpegts/examples/dump.rs +0 -44
- crates/ec-mpegts/examples/offs.rs +0 -22
- crates/ec-mpegts/examples/psdump.rs +0 -43
- crates/ec-ogg/examples/benchp1.rs +0 -47
- crates/ec-riff/examples/benchp1.rs +0 -68
crates/ec-matroska/examples/bench.rsdeleted+0 -87
| @@ -1,87 +0,0 @@ | |||
| 1 | -//! bench: Matroska demux throughput for lanes/bench.md ("lane benchrest"). | ||
| 2 | -//! | ||
| 3 | -//! usage: | ||
| 4 | -//! bench demux <in.mkv> <out_prefix> [reps] | ||
| 5 | -//! | ||
| 6 | -//! `demux` opens the file with `MatroskaDemuxer` and reads every packet of every track, `reps` | ||
| 7 | -//! times (default 5), and keeps the best wall time. It prints packets per second and payload MB/s. | ||
| 8 | -//! After timing, one untimed pass writes each track's packet payloads, concatenated in order, to | ||
| 9 | -//! `<out_prefix>.s<N>.bin` so the bytes can be compared with ffmpeg's `-c copy -f data` output. | ||
| 10 | -use std::fs::File; | ||
| 11 | -use std::hint::black_box; | ||
| 12 | -use std::io::BufReader; | ||
| 13 | -use std::time::Instant; | ||
| 14 | - | ||
| 15 | -use ec_core::{Demuxer, Packet, StreamInfo}; | ||
| 16 | -use ec_matroska::MatroskaDemuxer; | ||
| 17 | - | ||
| 18 | -/// Read every packet of the file once, in file order. | ||
| 19 | -fn read_all(path: &str) -> (Vec<StreamInfo>, Vec<Packet>) { | ||
| 20 | - let mut demux = | ||
| 21 | - MatroskaDemuxer::new(BufReader::new(File::open(path).expect("open"))).expect("mkv"); | ||
| 22 | - let streams = demux.streams().to_vec(); | ||
| 23 | - let mut packets = Vec::new(); | ||
| 24 | - loop { | ||
| 25 | - match demux.next_packet() { | ||
| 26 | - Ok(p) => packets.push(p), | ||
| 27 | - Err(e) if e.is_eof() => break, | ||
| 28 | - Err(e) => panic!("demux: {e}"), | ||
| 29 | - } | ||
| 30 | - } | ||
| 31 | - (streams, packets) | ||
| 32 | -} | ||
| 33 | - | ||
| 34 | -/// One timed demux pass: sums the payload bytes so the work cannot be skipped. | ||
| 35 | -fn demux_pass(path: &str) -> (usize, u64) { | ||
| 36 | - let mut demux = | ||
| 37 | - MatroskaDemuxer::new(BufReader::new(File::open(path).expect("open"))).expect("mkv"); | ||
| 38 | - let (mut n, mut bytes) = (0usize, 0u64); | ||
| 39 | - loop { | ||
| 40 | - match demux.next_packet() { | ||
| 41 | - Ok(p) => { | ||
| 42 | - n += 1; | ||
| 43 | - bytes += p.data.len() as u64; | ||
| 44 | - black_box(&p.data); | ||
| 45 | - } | ||
| 46 | - Err(e) if e.is_eof() => break, | ||
| 47 | - Err(e) => panic!("demux: {e}"), | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | - (n, bytes) | ||
| 51 | -} | ||
| 52 | - | ||
| 53 | -fn main() { | ||
| 54 | - let args: Vec<String> = std::env::args().collect(); | ||
| 55 | - match args.get(1).map(String::as_str) { | ||
| 56 | - Some("demux") if args.len() >= 4 => { | ||
| 57 | - let reps: usize = args.get(4).map_or(5, |s| s.parse().expect("reps")); | ||
| 58 | - assert!(reps >= 1, "reps must be at least 1"); | ||
| 59 | - let file_bytes = std::fs::metadata(&args[2]).expect("stat").len(); | ||
| 60 | - let (mut packets, mut bytes) = (0usize, 0u64); | ||
| 61 | - let mut best = f64::MAX; | ||
| 62 | - for _ in 0..reps { | ||
| 63 | - let t = Instant::now(); | ||
| 64 | - (packets, bytes) = demux_pass(black_box(&args[2])); | ||
| 65 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 66 | - } | ||
| 67 | - // Untimed: per-track payload dumps for the ffmpeg byte comparison. | ||
| 68 | - let (streams, all) = read_all(&args[2]); | ||
| 69 | - for s in &streams { | ||
| 70 | - let mut dump = Vec::new(); | ||
| 71 | - for p in all.iter().filter(|p| p.stream == s.index) { | ||
| 72 | - dump.extend_from_slice(&p.data); | ||
| 73 | - } | ||
| 74 | - std::fs::write(format!("{}.s{}.bin", args[3], s.index), &dump).expect("write dump"); | ||
| 75 | - } | ||
| 76 | - println!( | ||
| 77 | - "packets={packets} payload_bytes={bytes} file_bytes={file_bytes} best_demux_s={best:.4} packets_per_s={:.0} mb_per_s={:.2} reps={reps}", | ||
| 78 | - packets as f64 / best, | ||
| 79 | - bytes as f64 / best / 1e6 | ||
| 80 | - ); | ||
| 81 | - } | ||
| 82 | - _ => { | ||
| 83 | - eprintln!("usage: bench demux <in.mkv> <out_prefix> [reps]"); | ||
| 84 | - std::process::exit(2); | ||
| 85 | - } | ||
| 86 | - } | ||
| 87 | -} | ||
crates/ec-mp4/examples/bench.rsdeleted+0 -119
| @@ -1,119 +0,0 @@ | |||
| 1 | -//! bench: MP4 demux and mux throughput for lanes/bench.md ("lane benchaudio"). | ||
| 2 | -//! | ||
| 3 | -//! usage: | ||
| 4 | -//! bench demux <in.mp4> <out_prefix> [reps] | ||
| 5 | -//! bench mux <in.mp4> <out.mp4> [reps] | ||
| 6 | -//! | ||
| 7 | -//! `demux` opens the file with `Mp4Demuxer` and reads every packet of every track, `reps` times | ||
| 8 | -//! (default 5), and keeps the best wall time. It prints packets per second and payload MB/s. After | ||
| 9 | -//! timing, one untimed pass writes each track's packet payloads, concatenated in order, to | ||
| 10 | -//! `<out_prefix>.s<N>.bin` so the bytes can be compared with ffmpeg's `-c copy -f data` output. | ||
| 11 | -//! `mux` demuxes the input once (untimed), then times writing all packets into a new MP4 with | ||
| 12 | -//! `Mp4Muxer`, best of `reps`; the last output is kept at `out.mp4`. | ||
| 13 | -use std::fs::File; | ||
| 14 | -use std::hint::black_box; | ||
| 15 | -use std::io::BufReader; | ||
| 16 | -use std::time::Instant; | ||
| 17 | - | ||
| 18 | -use ec_core::{Demuxer, Muxer, Packet, StreamInfo}; | ||
| 19 | -use ec_mp4::{Mp4Demuxer, Mp4Muxer}; | ||
| 20 | - | ||
| 21 | -/// Read every packet of the file once, in file order. | ||
| 22 | -fn read_all(path: &str) -> (Vec<StreamInfo>, Vec<Packet>) { | ||
| 23 | - let mut demux = Mp4Demuxer::new(BufReader::new(File::open(path).expect("open"))).expect("mp4"); | ||
| 24 | - let streams = demux.streams().to_vec(); | ||
| 25 | - let mut packets = Vec::new(); | ||
| 26 | - loop { | ||
| 27 | - match demux.next_packet() { | ||
| 28 | - Ok(p) => packets.push(p), | ||
| 29 | - Err(e) if e.is_eof() => break, | ||
| 30 | - Err(e) => panic!("demux: {e}"), | ||
| 31 | - } | ||
| 32 | - } | ||
| 33 | - (streams, packets) | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -/// One timed demux pass: sums the payload bytes so the work cannot be skipped. | ||
| 37 | -fn demux_pass(path: &str) -> (usize, u64) { | ||
| 38 | - let mut demux = Mp4Demuxer::new(BufReader::new(File::open(path).expect("open"))).expect("mp4"); | ||
| 39 | - let (mut n, mut bytes) = (0usize, 0u64); | ||
| 40 | - loop { | ||
| 41 | - match demux.next_packet() { | ||
| 42 | - Ok(p) => { | ||
| 43 | - n += 1; | ||
| 44 | - bytes += p.data.len() as u64; | ||
| 45 | - black_box(&p.data); | ||
| 46 | - } | ||
| 47 | - Err(e) if e.is_eof() => break, | ||
| 48 | - Err(e) => panic!("demux: {e}"), | ||
| 49 | - } | ||
| 50 | - } | ||
| 51 | - (n, bytes) | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | -/// One timed mux pass into `out`. | ||
| 55 | -fn mux_pass(out: &str, streams: &[StreamInfo], packets: &[Packet]) { | ||
| 56 | - let file = File::create(out).expect("create"); | ||
| 57 | - let mut mux = Mp4Muxer::new(file).expect("muxer"); | ||
| 58 | - for s in streams { | ||
| 59 | - mux.add_stream(s.clone()).expect("add stream"); | ||
| 60 | - } | ||
| 61 | - for p in packets { | ||
| 62 | - mux.write_packet(p).expect("write packet"); | ||
| 63 | - } | ||
| 64 | - mux.finish().expect("finish"); | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | -fn main() { | ||
| 68 | - let args: Vec<String> = std::env::args().collect(); | ||
| 69 | - match args.get(1).map(String::as_str) { | ||
| 70 | - Some("demux") if args.len() >= 4 => { | ||
| 71 | - let reps: usize = args.get(4).map_or(5, |s| s.parse().expect("reps")); | ||
| 72 | - let file_bytes = std::fs::metadata(&args[2]).expect("stat").len(); | ||
| 73 | - let (mut packets, mut bytes) = (0usize, 0u64); | ||
| 74 | - let mut best = f64::MAX; | ||
| 75 | - for _ in 0..reps { | ||
| 76 | - let t = Instant::now(); | ||
| 77 | - (packets, bytes) = demux_pass(black_box(&args[2])); | ||
| 78 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 79 | - } | ||
| 80 | - // Untimed: per-track payload dumps for the ffmpeg byte comparison. | ||
| 81 | - let (streams, all) = read_all(&args[2]); | ||
| 82 | - for s in &streams { | ||
| 83 | - let mut dump = Vec::new(); | ||
| 84 | - for p in all.iter().filter(|p| p.stream == s.index) { | ||
| 85 | - dump.extend_from_slice(&p.data); | ||
| 86 | - } | ||
| 87 | - std::fs::write(format!("{}.s{}.bin", args[3], s.index), &dump).expect("write dump"); | ||
| 88 | - } | ||
| 89 | - println!( | ||
| 90 | - "packets={packets} payload_bytes={bytes} file_bytes={file_bytes} best_demux_s={best:.4} packets_per_s={:.0} mb_per_s={:.2} reps={reps}", | ||
| 91 | - packets as f64 / best, | ||
| 92 | - bytes as f64 / best / 1e6 | ||
| 93 | - ); | ||
| 94 | - } | ||
| 95 | - Some("mux") if args.len() >= 4 => { | ||
| 96 | - let reps: usize = args.get(4).map_or(5, |s| s.parse().expect("reps")); | ||
| 97 | - let (streams, packets) = read_all(&args[2]); | ||
| 98 | - let bytes: u64 = packets.iter().map(|p| p.data.len() as u64).sum(); | ||
| 99 | - let mut best = f64::MAX; | ||
| 100 | - for _ in 0..reps { | ||
| 101 | - let t = Instant::now(); | ||
| 102 | - mux_pass(black_box(&args[3]), &streams, &packets); | ||
| 103 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 104 | - } | ||
| 105 | - println!( | ||
| 106 | - "packets={} payload_bytes={bytes} best_mux_s={best:.4} packets_per_s={:.0} mb_per_s={:.2} reps={reps}", | ||
| 107 | - packets.len(), | ||
| 108 | - packets.len() as f64 / best, | ||
| 109 | - bytes as f64 / best / 1e6 | ||
| 110 | - ); | ||
| 111 | - } | ||
| 112 | - _ => { | ||
| 113 | - eprintln!( | ||
| 114 | - "usage: bench demux <in.mp4> <out_prefix> [reps]\n bench mux <in.mp4> <out.mp4> [reps]" | ||
| 115 | - ); | ||
| 116 | - std::process::exit(2); | ||
| 117 | - } | ||
| 118 | - } | ||
| 119 | -} | ||
crates/ec-mpegts/examples/bench.rsdeleted+0 -45
| @@ -1,45 +0,0 @@ | |||
| 1 | -//! Open, full read and seek timings: `cargo run --release -p ec-mpegts --example bench -- file`. | ||
| 2 | -use std::fs::File; | ||
| 3 | -use std::io::BufReader; | ||
| 4 | -use std::time::Instant; | ||
| 5 | - | ||
| 6 | -use ec_core::registry::{Demuxer, SeekMode}; | ||
| 7 | -use ec_core::{TimeBase, Timestamp}; | ||
| 8 | - | ||
| 9 | -fn main() { | ||
| 10 | - let path = std::env::args().nth(1).expect("usage: bench <file>"); | ||
| 11 | - let t = Instant::now(); | ||
| 12 | - let mut d = | ||
| 13 | - ec_mpegts::TsDemuxer::new(BufReader::new(File::open(&path).expect("open"))).expect("demux"); | ||
| 14 | - println!("open {:?}, duration {:?}", t.elapsed(), d.duration_secs()); | ||
| 15 | - let t = Instant::now(); | ||
| 16 | - let (mut n, mut bytes) = (0u64, 0u64); | ||
| 17 | - while let Ok(p) = d.next_packet() { | ||
| 18 | - n += 1; | ||
| 19 | - bytes += p.data.len() as u64; | ||
| 20 | - } | ||
| 21 | - let e = t.elapsed(); | ||
| 22 | - println!( | ||
| 23 | - "read {n} packets, {} MB in {e:?} ({:.0} MB/s)", | ||
| 24 | - bytes >> 20, | ||
| 25 | - bytes as f64 / 1e6 / e.as_secs_f64() | ||
| 26 | - ); | ||
| 27 | - let dur = d.duration_secs().unwrap_or(1.0); | ||
| 28 | - for frac in [0.1, 0.5, 0.9, 0.999] { | ||
| 29 | - let t = Instant::now(); | ||
| 30 | - let target = (dur * frac * 90_000.0) as i64 + d.streams()[0].start_time.unwrap_or(0); | ||
| 31 | - d.seek( | ||
| 32 | - 0, | ||
| 33 | - Timestamp::new(target, TimeBase::new(1, 90_000)), | ||
| 34 | - SeekMode::SyncBefore, | ||
| 35 | - ) | ||
| 36 | - .unwrap(); | ||
| 37 | - let p = d.next_packet().unwrap(); | ||
| 38 | - println!( | ||
| 39 | - "seek {frac}: {:?} -> pts {:?} key {}", | ||
| 40 | - t.elapsed(), | ||
| 41 | - p.pts, | ||
| 42 | - p.flags.keyframe | ||
| 43 | - ); | ||
| 44 | - } | ||
| 45 | -} | ||
crates/ec-mpegts/examples/dump.rsdeleted+0 -44
| @@ -1,44 +0,0 @@ | |||
| 1 | -//! Lists the programs, tracks and streams of a transport stream and counts its | ||
| 2 | -//! packets: `cargo run -p ec-mpegts --example dump -- file.m2ts`. | ||
| 3 | - | ||
| 4 | -use std::fs::File; | ||
| 5 | -use std::io::BufReader; | ||
| 6 | - | ||
| 7 | -use ec_core::registry::Demuxer; | ||
| 8 | -use ec_mpegts::TsDemuxer; | ||
| 9 | - | ||
| 10 | -fn main() { | ||
| 11 | - let path = std::env::args().nth(1).expect("usage: dump <file>"); | ||
| 12 | - let mut d = TsDemuxer::new(BufReader::new(File::open(&path).expect("open"))).expect("demux"); | ||
| 13 | - println!("packet size {} bdav {}", d.packet_size(), d.is_bdav()); | ||
| 14 | - for p in d.programs() { | ||
| 15 | - println!( | ||
| 16 | - "program {} pmt {:#x} pcr {:?} streams {}", | ||
| 17 | - p.number, | ||
| 18 | - p.pmt_pid, | ||
| 19 | - p.pcr_pid, | ||
| 20 | - p.streams.len() | ||
| 21 | - ); | ||
| 22 | - } | ||
| 23 | - for t in d.tracks() { | ||
| 24 | - println!( | ||
| 25 | - "track pid {:#x} type {:#x} {:?} stream {:?} refusal {:?}", | ||
| 26 | - t.pid, t.stream_type, t.kind, t.stream, t.refusal | ||
| 27 | - ); | ||
| 28 | - } | ||
| 29 | - for s in d.streams() { | ||
| 30 | - println!( | ||
| 31 | - "stream {} {} start {:?} duration {:?}", | ||
| 32 | - s.index, | ||
| 33 | - s.params.codec.name(), | ||
| 34 | - s.start_time, | ||
| 35 | - s.duration | ||
| 36 | - ); | ||
| 37 | - } | ||
| 38 | - println!("duration {:?}", d.duration_secs()); | ||
| 39 | - let mut counts = vec![0u64; d.streams().len()]; | ||
| 40 | - while let Ok(p) = d.next_packet() { | ||
| 41 | - counts[p.stream as usize] += 1; | ||
| 42 | - } | ||
| 43 | - println!("packets {counts:?} stats {:?}", d.stats()); | ||
| 44 | -} | ||
crates/ec-mpegts/examples/offs.rsdeleted+0 -22
| @@ -1,22 +0,0 @@ | |||
| 1 | -use ec_core::registry::Demuxer; | ||
| 2 | -use std::fs::File; | ||
| 3 | -use std::io::BufReader; | ||
| 4 | -fn main() { | ||
| 5 | - let path = std::env::args().nth(1).unwrap(); | ||
| 6 | - let mut d = ec_mpegts::TsDemuxer::new(BufReader::new(File::open(path).unwrap())).unwrap(); | ||
| 7 | - let mut n = 0; | ||
| 8 | - while let Ok(p) = d.next_packet() { | ||
| 9 | - println!( | ||
| 10 | - "{} off {} pts {:?} dur {:?} len {}", | ||
| 11 | - p.stream, | ||
| 12 | - d.last_packet_offset(), | ||
| 13 | - p.pts, | ||
| 14 | - p.duration, | ||
| 15 | - p.data.len() | ||
| 16 | - ); | ||
| 17 | - n += 1; | ||
| 18 | - if n > 14 { | ||
| 19 | - break; | ||
| 20 | - } | ||
| 21 | - } | ||
| 22 | -} | ||
crates/ec-mpegts/examples/psdump.rsdeleted+0 -43
| @@ -1,43 +0,0 @@ | |||
| 1 | -use ec_core::registry::Demuxer; | ||
| 2 | -use ec_mpegts::PsDemuxer; | ||
| 3 | -fn main() { | ||
| 4 | - let p = std::env::args().nth(1).unwrap(); | ||
| 5 | - let mut d = PsDemuxer::new(std::io::BufReader::new(std::fs::File::open(p).unwrap())).unwrap(); | ||
| 6 | - for s in d.streams() { | ||
| 7 | - println!( | ||
| 8 | - "stream {} {:?} start {:?} dur {:?}", | ||
| 9 | - s.index, s.params.codec, s.start_time, s.duration | ||
| 10 | - ); | ||
| 11 | - } | ||
| 12 | - for t in d.tracks() { | ||
| 13 | - println!("track {:04x} {:?} {:?}", t.pid, t.kind, t.refusal); | ||
| 14 | - } | ||
| 15 | - println!("dur {:?} stats {:?}", d.duration_secs(), d.stats()); | ||
| 16 | - if let Some(t) = std::env::args().nth(3) { | ||
| 17 | - use ec_core::registry::SeekMode; | ||
| 18 | - let t: i64 = t.parse().unwrap(); | ||
| 19 | - d.seek( | ||
| 20 | - 0, | ||
| 21 | - ec_core::Timestamp::new(t, ec_core::TimeBase::new(1, 90000)), | ||
| 22 | - SeekMode::SyncBefore, | ||
| 23 | - ) | ||
| 24 | - .unwrap(); | ||
| 25 | - println!("landing {}", d.last_packet_offset()); | ||
| 26 | - } | ||
| 27 | - let n: usize = std::env::args() | ||
| 28 | - .nth(2) | ||
| 29 | - .map(|x| x.parse().unwrap()) | ||
| 30 | - .unwrap_or(40); | ||
| 31 | - for _ in 0..n { | ||
| 32 | - let Ok(p) = d.next_packet() else { break }; | ||
| 33 | - println!( | ||
| 34 | - "s{} pts {:?} dts {:?} k{} len {} off {}", | ||
| 35 | - p.stream, | ||
| 36 | - p.pts, | ||
| 37 | - p.dts, | ||
| 38 | - p.flags.keyframe as u8, | ||
| 39 | - p.data.len(), | ||
| 40 | - d.last_packet_offset() | ||
| 41 | - ); | ||
| 42 | - } | ||
| 43 | -} | ||
crates/ec-ogg/examples/benchp1.rsdeleted+0 -47
| @@ -1,47 +0,0 @@ | |||
| 1 | -//! benchp1: Ogg demux throughput for lanes/bench.md ("lane benchp1"). | ||
| 2 | -//! | ||
| 3 | -//! usage: benchp1 <file.ogg> [reps] | ||
| 4 | -//! | ||
| 5 | -//! Opens the file and reads every packet with `OggDemuxer`, `reps` times (default 5), keeping the | ||
| 6 | -//! best wall time. Prints the packet count and byte total (checked against ffprobe) and the time. | ||
| 7 | -use std::fs::File; | ||
| 8 | -use std::hint::black_box; | ||
| 9 | -use std::io::BufReader; | ||
| 10 | -use std::time::Instant; | ||
| 11 | - | ||
| 12 | -use ec_core::Demuxer; | ||
| 13 | -use ec_ogg::OggDemuxer; | ||
| 14 | - | ||
| 15 | -/// Demux the whole file once: (packets, bytes). | ||
| 16 | -fn demux_once(path: &str) -> (u64, u64) { | ||
| 17 | - let mut demux = OggDemuxer::open(BufReader::new(File::open(path).expect("open"))).expect("open ogg"); | ||
| 18 | - let (mut packets, mut bytes) = (0u64, 0u64); | ||
| 19 | - loop { | ||
| 20 | - match demux.next_packet() { | ||
| 21 | - Ok(p) => { | ||
| 22 | - packets += 1; | ||
| 23 | - bytes += p.data.len() as u64; | ||
| 24 | - black_box(&p); | ||
| 25 | - } | ||
| 26 | - Err(e) if e.is_eof() => break, | ||
| 27 | - Err(e) => panic!("demux: {e}"), | ||
| 28 | - } | ||
| 29 | - } | ||
| 30 | - (packets, bytes) | ||
| 31 | -} | ||
| 32 | - | ||
| 33 | -fn main() { | ||
| 34 | - let args: Vec<String> = std::env::args().collect(); | ||
| 35 | - let reps: usize = args.get(2).map_or(5, |s| s.parse().expect("reps")); | ||
| 36 | - let (packets, bytes) = demux_once(&args[1]); | ||
| 37 | - let mut best = f64::MAX; | ||
| 38 | - for _ in 0..reps { | ||
| 39 | - let t = Instant::now(); | ||
| 40 | - black_box(demux_once(black_box(&args[1]))); | ||
| 41 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 42 | - } | ||
| 43 | - println!( | ||
| 44 | - "packets={packets} bytes={bytes} best_demux_s={best:.4} mb_s={:.2} reps={reps}", | ||
| 45 | - bytes as f64 / best / 1e6 | ||
| 46 | - ); | ||
| 47 | -} | ||
crates/ec-riff/examples/benchp1.rsdeleted+0 -68
| @@ -1,68 +0,0 @@ | |||
| 1 | -//! benchp1: RIFF/WAVE read and write throughput for lanes/bench.md ("lane benchp1"). | ||
| 2 | -//! | ||
| 3 | -//! usage: | ||
| 4 | -//! benchp1 read <in.wav> [reps] | ||
| 5 | -//! Opens the file and decodes every sample to i32 with `WavReader::read_all_i32`, `reps` | ||
| 6 | -//! times (default 5), keeping the best wall time. | ||
| 7 | -//! benchp1 write <in.wav> <out.wav> <riff|rf64> [reps] | ||
| 8 | -//! Reads the samples once (untimed), then writes them back with `WavWriter` at the same | ||
| 9 | -//! spec, `reps` times (default 5), keeping the best wall time. `riff` takes the default | ||
| 10 | -//! header; `rf64` forces the RF64 header (rf64_threshold 0). The last output is kept at | ||
| 11 | -//! <out.wav> for the md5 round-trip check. | ||
| 12 | -use std::hint::black_box; | ||
| 13 | -use std::time::Instant; | ||
| 14 | - | ||
| 15 | -use ec_riff::{RF64_THRESHOLD, WavOptions, WavReader, WavWriter}; | ||
| 16 | - | ||
| 17 | -fn read_once(path: &str) -> (usize, f64) { | ||
| 18 | - let t = Instant::now(); | ||
| 19 | - let mut reader = WavReader::open(path).expect("open wav"); | ||
| 20 | - let samples = reader.read_all_i32().expect("read samples"); | ||
| 21 | - let secs = t.elapsed().as_secs_f64(); | ||
| 22 | - black_box(&samples); | ||
| 23 | - (samples.len(), secs) | ||
| 24 | -} | ||
| 25 | - | ||
| 26 | -fn main() { | ||
| 27 | - let args: Vec<String> = std::env::args().collect(); | ||
| 28 | - match args.get(1).map(String::as_str) { | ||
| 29 | - Some("read") => { | ||
| 30 | - let reps: usize = args.get(3).map_or(5, |s| s.parse().expect("reps")); | ||
| 31 | - let bytes = std::fs::metadata(&args[2]).expect("stat").len(); | ||
| 32 | - let (samples, _) = read_once(&args[2]); | ||
| 33 | - let best = (0..reps).map(|_| read_once(&args[2]).1).fold(f64::MAX, f64::min); | ||
| 34 | - println!( | ||
| 35 | - "samples={samples} bytes={bytes} best_read_s={best:.4} mb_s={:.2} reps={reps}", | ||
| 36 | - bytes as f64 / best / 1e6 | ||
| 37 | - ); | ||
| 38 | - } | ||
| 39 | - Some("write") => { | ||
| 40 | - let (input, out, mode) = (&args[2], &args[3], args[4].as_str()); | ||
| 41 | - let reps: usize = args.get(5).map_or(5, |s| s.parse().expect("reps")); | ||
| 42 | - let mut reader = WavReader::open(input).expect("open wav"); | ||
| 43 | - let spec = reader.spec(); | ||
| 44 | - let samples = reader.read_all_i32().expect("read samples"); | ||
| 45 | - let frames = samples.len() as u64 / u64::from(spec.channels); | ||
| 46 | - let options = match mode { | ||
| 47 | - "riff" => WavOptions { expected_frames: frames, rf64_threshold: RF64_THRESHOLD }, | ||
| 48 | - "rf64" => WavOptions { expected_frames: frames, rf64_threshold: 0 }, | ||
| 49 | - _ => panic!("mode must be riff or rf64"), | ||
| 50 | - }; | ||
| 51 | - let data_bytes = samples.len() as u64 * u64::from(spec.bits_per_sample) / 8; | ||
| 52 | - let mut best = f64::MAX; | ||
| 53 | - for _ in 0..reps { | ||
| 54 | - let t = Instant::now(); | ||
| 55 | - let mut w = WavWriter::create_with_options(out, spec, options).expect("create"); | ||
| 56 | - w.write_samples(&samples).expect("write samples"); | ||
| 57 | - w.finalize().expect("finalize"); | ||
| 58 | - best = best.min(t.elapsed().as_secs_f64()); | ||
| 59 | - } | ||
| 60 | - println!( | ||
| 61 | - "mode={mode} samples={} data_bytes={data_bytes} best_write_s={best:.4} mb_s={:.2} reps={reps}", | ||
| 62 | - samples.len(), | ||
| 63 | - data_bytes as f64 / best / 1e6 | ||
| 64 | - ); | ||
| 65 | - } | ||
| 66 | - _ => panic!("usage: benchp1 read <in.wav> [reps] | write <in.wav> <out.wav> <riff|rf64> [reps]"), | ||
| 67 | - } | ||
| 68 | -} | ||