U20: drop ec-image and ec-inflate bench examples (benchmarks live in ec-bench)
Browse files at this commit4e4fcb8b410123eeb8b7cc35495ef3c1e42697a8Parent: b2b318b2 changed files +0 -142
crates/ec-image/examples/bench.rsdeleted+0 -73
| @@ -1,73 +0,0 @@ | ||
| 1 | -//! bench: still-image decode and PNG encode rows for lanes/bench.md ("lane benchrest"). | |
| 2 | -//! | |
| 3 | -//! usage: | |
| 4 | -//! bench png-dec <in.png> <out.rgb> [reps] | |
| 5 | -//! bench jpeg-dec <in.jpg> <out.rgb> [reps] | |
| 6 | -//! bench png-enc <in.rgba> <width> <height> <out.png> [reps] | |
| 7 | -//! | |
| 8 | -//! `png-dec` and `jpeg-dec` decode the file with `ec_image::decode`, `reps` times (default 5), and | |
| 9 | -//! keep the best wall time. After timing, the last decode is converted with `to_rgb8` and written to | |
| 10 | -//! `<out.rgb>` (untimed) so the pixels can be compared with ffmpeg's `-f rawvideo -pix_fmt rgb24`. | |
| 11 | -//! `png-enc` encodes raw RGBA8 with `ec_image::png_encode::encode_rgba8`, best of `reps`, and writes | |
| 12 | -//! the last PNG to `<out.png>`. | |
| 13 | -use std::hint::black_box; | |
| 14 | -use std::time::Instant; | |
| 15 | - | |
| 16 | -fn main() { | |
| 17 | - let args: Vec<String> = std::env::args().collect(); | |
| 18 | - match args.get(1).map(String::as_str) { | |
| 19 | - Some("png-dec" | "jpeg-dec") if args.len() >= 4 => { | |
| 20 | - let reps: usize = args.get(4).map_or(5, |s| s.parse().expect("reps")); | |
| 21 | - assert!(reps >= 1, "reps must be at least 1"); | |
| 22 | - let data = std::fs::read(&args[2]).expect("read input"); | |
| 23 | - let mut best = f64::MAX; | |
| 24 | - let mut last = None; | |
| 25 | - for _ in 0..reps { | |
| 26 | - let t = Instant::now(); | |
| 27 | - let img = ec_image::decode(black_box(&data)).expect("decode"); | |
| 28 | - best = best.min(t.elapsed().as_secs_f64()); | |
| 29 | - last = Some(img); | |
| 30 | - } | |
| 31 | - let img = last.expect("at least one rep"); | |
| 32 | - let (w, h) = img.dimensions(); | |
| 33 | - let rgb = img.to_rgb8(); | |
| 34 | - std::fs::write(&args[3], &rgb).expect("write output"); | |
| 35 | - let mpix = f64::from(w) * f64::from(h) / 1e6; | |
| 36 | - println!( | |
| 37 | - "width={w} height={h} channels={} best_decode_s={best:.4} mpix_per_s={:.2} mb_per_s={:.2} out_bytes={} reps={reps}", | |
| 38 | - img.pixels.channels(), | |
| 39 | - mpix / best, | |
| 40 | - rgb.len() as f64 / best / 1e6, | |
| 41 | - rgb.len() | |
| 42 | - ); | |
| 43 | - } | |
| 44 | - Some("png-enc") if args.len() >= 6 => { | |
| 45 | - let reps: usize = args.get(6).map_or(5, |s| s.parse().expect("reps")); | |
| 46 | - assert!(reps >= 1, "reps must be at least 1"); | |
| 47 | - let w: u32 = args[3].parse().expect("width"); | |
| 48 | - let h: u32 = args[4].parse().expect("height"); | |
| 49 | - let raw = std::fs::read(&args[2]).expect("read input"); | |
| 50 | - let mut best = f64::MAX; | |
| 51 | - let mut out = Vec::new(); | |
| 52 | - for _ in 0..reps { | |
| 53 | - let t = Instant::now(); | |
| 54 | - out = ec_image::png_encode::encode_rgba8(w, h, black_box(&raw)).expect("encode"); | |
| 55 | - best = best.min(t.elapsed().as_secs_f64()); | |
| 56 | - } | |
| 57 | - std::fs::write(&args[5], &out).expect("write output"); | |
| 58 | - let mpix = f64::from(w) * f64::from(h) / 1e6; | |
| 59 | - println!( | |
| 60 | - "width={w} height={h} best_encode_s={best:.4} mpix_per_s={:.2} mb_per_s={:.2} out_bytes={} reps={reps}", | |
| 61 | - mpix / best, | |
| 62 | - raw.len() as f64 / best / 1e6, | |
| 63 | - out.len() | |
| 64 | - ); | |
| 65 | - } | |
| 66 | - _ => { | |
| 67 | - eprintln!( | |
| 68 | - "usage: bench png-dec <in.png> <out.rgb> [reps]\n bench jpeg-dec <in.jpg> <out.rgb> [reps]\n bench png-enc <in.rgba> <width> <height> <out.png> [reps]" | |
| 69 | - ); | |
| 70 | - std::process::exit(2); | |
| 71 | - } | |
| 72 | - } | |
| 73 | -} |
crates/ec-inflate/examples/bench.rsdeleted+0 -69
| @@ -1,69 +0,0 @@ | ||
| 1 | -//! bench: zlib inflate rows for lanes/bench.md ("lane benchrest"). | |
| 2 | -//! | |
| 3 | -//! usage: | |
| 4 | -//! bench zlib <in.zlib> <out.bin> [reps] | |
| 5 | -//! bench blocks <in.blocks> <out.bin> [reps] | |
| 6 | -//! | |
| 7 | -//! `zlib` inflates one zlib stream with `inflate_zlib`, `reps` times (default 5), and keeps the | |
| 8 | -//! best wall time. `blocks` reads a sequence of `[u32 little-endian length][zlib stream]` records | |
| 9 | -//! (one per subtitle-sized packet) and inflates every record with `inflate_zlib`, timing the whole | |
| 10 | -//! loop. Both write the concatenated output of the last pass to `<out.bin>`, untimed, for the md5 | |
| 11 | -//! check against python's `zlib.decompress`. | |
| 12 | -use std::hint::black_box; | |
| 13 | -use std::time::Instant; | |
| 14 | - | |
| 15 | -/// Output ceiling passed to every call: far above the inputs used here, but not "no ceiling". | |
| 16 | -const LIMIT: usize = 1 << 30; | |
| 17 | - | |
| 18 | -fn split_blocks(data: &[u8]) -> Vec<&[u8]> { | |
| 19 | - let mut out = Vec::new(); | |
| 20 | - let mut at = 0usize; | |
| 21 | - while at < data.len() { | |
| 22 | - let len = u32::from_le_bytes(data[at..at + 4].try_into().expect("4 bytes")) as usize; | |
| 23 | - at += 4; | |
| 24 | - out.push(&data[at..at + len]); | |
| 25 | - at += len; | |
| 26 | - } | |
| 27 | - out | |
| 28 | -} | |
| 29 | - | |
| 30 | -fn main() { | |
| 31 | - let args: Vec<String> = std::env::args().collect(); | |
| 32 | - match args.get(1).map(String::as_str) { | |
| 33 | - Some(mode @ ("zlib" | "blocks")) if args.len() >= 4 => { | |
| 34 | - let reps: usize = args.get(4).map_or(5, |s| s.parse().expect("reps")); | |
| 35 | - assert!(reps >= 1, "reps must be at least 1"); | |
| 36 | - let data = std::fs::read(&args[2]).expect("read input"); | |
| 37 | - let blocks = if mode == "blocks" { split_blocks(&data) } else { Vec::new() }; | |
| 38 | - let mut best = f64::MAX; | |
| 39 | - let mut out = Vec::new(); | |
| 40 | - for _ in 0..reps { | |
| 41 | - let t = Instant::now(); | |
| 42 | - out = Vec::new(); | |
| 43 | - if mode == "zlib" { | |
| 44 | - out = ec_inflate::inflate_zlib(black_box(&data), LIMIT).expect("inflate"); | |
| 45 | - } else { | |
| 46 | - for b in &blocks { | |
| 47 | - let v = ec_inflate::inflate_zlib(black_box(b), LIMIT).expect("inflate block"); | |
| 48 | - out.extend_from_slice(&v); | |
| 49 | - } | |
| 50 | - } | |
| 51 | - best = best.min(t.elapsed().as_secs_f64()); | |
| 52 | - } | |
| 53 | - std::fs::write(&args[3], &out).expect("write output"); | |
| 54 | - let streams = if mode == "blocks" { blocks.len() } else { 1 }; | |
| 55 | - println!( | |
| 56 | - "mode={mode} streams={streams} in_bytes={} out_bytes={} best_inflate_s={best:.4} mb_per_s={:.2} reps={reps}", | |
| 57 | - data.len(), | |
| 58 | - out.len(), | |
| 59 | - out.len() as f64 / best / 1e6 | |
| 60 | - ); | |
| 61 | - } | |
| 62 | - _ => { | |
| 63 | - eprintln!( | |
| 64 | - "usage: bench zlib <in.zlib> <out.bin> [reps]\n bench blocks <in.blocks> <out.bin> [reps]" | |
| 65 | - ); | |
| 66 | - std::process::exit(2); | |
| 67 | - } | |
| 68 | - } | |
| 69 | -} |