From 1b6a04ca5504955c571d1c97504fb45ea0befee4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Mon, 8 Jan 2024 01:21:28 +0400 Subject: Initial vendor packages Signed-off-by: Valentin Popov --- vendor/exr/benches/pixel_format_conversion.rs | 119 ++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 vendor/exr/benches/pixel_format_conversion.rs (limited to 'vendor/exr/benches/pixel_format_conversion.rs') diff --git a/vendor/exr/benches/pixel_format_conversion.rs b/vendor/exr/benches/pixel_format_conversion.rs new file mode 100644 index 0000000..3d1ba93 --- /dev/null +++ b/vendor/exr/benches/pixel_format_conversion.rs @@ -0,0 +1,119 @@ +#[macro_use] +extern crate bencher; + +extern crate exr; +use exr::prelude::*; + +use bencher::Bencher; +use std::fs; +use std::io::Cursor; +use exr::image::pixel_vec::PixelVec; +use exr::io::Data; +use exr::block::samples::FromNativeSample; + +const F32_ZIPS_PATH: &'static str = "tests/images/valid/custom/crowskull/crow_zips.exr"; +const F32_UNCOMPRESSED_PATH: &'static str = "tests/images/valid/custom/crowskull/crow_uncompressed.exr"; +const F16_UNCOMPRESSED_PATH: &'static str = "tests/images/valid/custom/crowskull/crow_uncompressed_half.exr"; +const F16_ZIP_PATH: &'static str = "tests/images/valid/custom/crowskull/crow_zip_half.exr"; + +/// Read an image from an in-memory buffer into its native f32 format +fn read_f32_as_f32_uncompressed_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_UNCOMPRESSED_PATH, false); +} + +/// Read image and convert the samples to u32 (from native f32) +fn read_f32_as_u32_uncompressed_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_UNCOMPRESSED_PATH, false); +} + +/// f16 is not natively supported by CPUs, which introduces unique performance pitfalls +fn read_f32_as_f16_uncompressed_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_UNCOMPRESSED_PATH, false); +} + +fn read_f16_as_f16_uncompressed_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_UNCOMPRESSED_PATH, false); +} + +fn read_f16_as_f32_uncompressed_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_UNCOMPRESSED_PATH, false); +} + +fn read_f16_as_u32_uncompressed_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_UNCOMPRESSED_PATH, false); +} + + +fn read_f32_as_f16_zips_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_ZIPS_PATH, false); +} + +fn read_f16_as_f32_zip_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_ZIP_PATH, false); +} + +fn read_f32_as_f16_zips_nthreads(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_ZIPS_PATH, true); +} + +fn read_f16_as_f32_zip_nthreads(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_ZIP_PATH, true); +} + +fn read_f32_as_f32_zips_nthreads(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_ZIPS_PATH, true); +} + +fn read_f16_as_f16_zip_nthreads(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_ZIP_PATH, true); +} + +fn read_f32_as_f32_zips_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F32_ZIPS_PATH, false); +} + +fn read_f16_as_f16_zip_1thread(bench: &mut Bencher) { + bench_read_image_rgba_as::(bench, F16_ZIP_PATH, false); +} + +fn bench_read_image_rgba_as(bench: &mut Bencher, path: &str, parallel: bool) { + let mut file = fs::read(path).unwrap(); + bencher::black_box(&mut file); + + bench.iter(||{ + let image = read_file_from_memory_as::(file.as_slice(), parallel); + bencher::black_box(image); + }) +} + +fn read_file_from_memory_as(file: &[u8], parallel: bool) -> RgbaImage> + where T: FromNativeSample +{ + let read = exr::prelude::read() + .no_deep_data().largest_resolution_level() + .rgba_channels(PixelVec::<(T, T, T, T)>::constructor, PixelVec::set_pixel) + .first_valid_layer().all_attributes(); + + let read = if parallel { read } else { read.non_parallel() }; + read.from_buffered(Cursor::new(file)).unwrap() +} + +benchmark_group!(pixel_format_conversion, + read_f32_as_f32_uncompressed_1thread, + read_f32_as_u32_uncompressed_1thread, + read_f32_as_f16_uncompressed_1thread, + read_f32_as_f16_zips_1thread, + read_f32_as_f16_zips_nthreads, + read_f32_as_f32_zips_nthreads, + read_f32_as_f32_zips_1thread, + + read_f16_as_f16_uncompressed_1thread, + read_f16_as_u32_uncompressed_1thread, + read_f16_as_f32_uncompressed_1thread, + read_f16_as_f32_zip_1thread, + read_f16_as_f32_zip_nthreads, + read_f16_as_f16_zip_nthreads, + read_f16_as_f16_zip_1thread, +); + +benchmark_main!(pixel_format_conversion); \ No newline at end of file -- cgit v1.2.3