From 8fccf7f07e979c298b6bf201a27e7059f768c053 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 2 Jan 2023 17:59:34 +0100 Subject: [PATCH 1/5] Read to f32 instead of f16 outside of conversion benchmarks; loading into f16 is only useful for GPU manipulation, there is no such type on the CPU. Don't reload the input data from disk every time. --- benches/read.rs | 84 +++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/benches/read.rs b/benches/read.rs index 57e44f52..b5938f2a 100644 --- a/benches/read.rs +++ b/benches/read.rs @@ -10,26 +10,32 @@ use std::io::Cursor; use exr::image::pixel_vec::PixelVec; /// Read uncompressed (always single core) -fn read_single_image_uncompressed_rgba(bench: &mut Bencher) { +fn read_single_image_uncompressed_non_parallel_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_uncompressed.exr").unwrap(); bench.iter(||{ - let path = "tests/images/valid/custom/crowskull/crow_uncompressed.exr"; + bencher::black_box(&mut file); - let image = read_all_rgba_layers_from_file( - path, PixelVec::<(f16,f16,f16,f16)>::constructor, PixelVec::set_pixel - ).unwrap(); + let image = exr::prelude::read() + .no_deep_data().largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers().all_attributes() + .non_parallel() + .from_buffered(Cursor::new(file.as_slice())).unwrap(); bencher::black_box(image); }) } /// Read from in-memory in parallel -fn read_single_image_uncompressed_from_buffer_rgba(bench: &mut Bencher) { - let file = fs::read("tests/images/valid/custom/crowskull/crow_uncompressed.exr").unwrap(); +fn read_single_image_uncompressed_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_uncompressed.exr").unwrap(); bench.iter(||{ + bencher::black_box(&mut file); + let image = exr::prelude::read() .no_deep_data().largest_resolution_level() - .rgba_channels(PixelVec::<(f16,f16,f16,f16)>::constructor, PixelVec::set_pixel) + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) .all_layers().all_attributes() .from_buffered(Cursor::new(file.as_slice())).unwrap(); @@ -39,31 +45,45 @@ fn read_single_image_uncompressed_from_buffer_rgba(bench: &mut Bencher) { /// Read with multi-core zip decompression fn read_single_image_zips_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); + bench.iter(||{ - let path = "tests/images/valid/custom/crowskull/crow_zips.exr"; + bencher::black_box(&mut file); - let image = read_all_rgba_layers_from_file( - path, PixelVec::<(f16,f16,f16,f16)>::constructor, PixelVec::set_pixel - ).unwrap(); + let image = exr::prelude::read() + .no_deep_data().largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers().all_attributes() + .from_buffered(Cursor::new(file.as_slice())).unwrap(); bencher::black_box(image); }) } -/// Read with multi-core RLE decompression -fn read_single_image_rle_all_channels(bench: &mut Bencher) { +/// Read without multi-core ZIP decompression +fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); + bench.iter(||{ - let path = "tests/images/valid/custom/crowskull/crow_rle.exr"; + bencher::black_box(&mut file); + + let image = exr::prelude::read() + .no_deep_data().largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers().all_attributes() + .non_parallel() + .from_buffered(Cursor::new(file.as_slice())).unwrap(); - let image = read_all_flat_layers_from_file(path).unwrap(); bencher::black_box(image); }) } -/// Read without multi-core RLE decompression -fn read_single_image_rle_non_parallel_all_channels(bench: &mut Bencher) { +/// Read with multi-core RLE decompression +fn read_single_image_rle_all_channels(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); + bench.iter(||{ - let path = "tests/images/valid/custom/crowskull/crow_rle.exr"; + bencher::black_box(&mut file); // copied from `read_all_flat_layers_from_file` and added `.non_parallel()` let image = exr::prelude::read() @@ -72,31 +92,35 @@ fn read_single_image_rle_non_parallel_all_channels(bench: &mut Bencher) { .all_channels() .all_layers() .all_attributes() - .non_parallel() - .from_file(path).unwrap(); + .from_buffered(Cursor::new(file.as_slice())).unwrap(); + bencher::black_box(image); }) } -/// Read without multi-core ZIP decompression -fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { +/// Read without multi-core RLE decompression +fn read_single_image_rle_non_parallel_all_channels(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); + bench.iter(||{ - let path = "tests/images/valid/custom/crowskull/crow_zips.exr"; + bencher::black_box(&mut file); + // copied from `read_all_flat_layers_from_file` and added `.non_parallel()` let image = exr::prelude::read() - .no_deep_data().largest_resolution_level() - .rgba_channels(PixelVec::<(f16,f16,f16,f16)>::constructor, PixelVec::set_pixel) - .all_layers().all_attributes() + .no_deep_data() + .largest_resolution_level() + .all_channels() + .all_layers() + .all_attributes() .non_parallel() - .from_file(path).unwrap(); + .from_buffered(Cursor::new(file.as_slice())).unwrap(); bencher::black_box(image); }) } - benchmark_group!(read, - read_single_image_uncompressed_from_buffer_rgba, + read_single_image_uncompressed_non_parallel_rgba, read_single_image_uncompressed_rgba, read_single_image_zips_rgba, read_single_image_rle_all_channels, From e2035101c166d9658dd974ea7ee2b72e2a3dc750 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 2 Jan 2023 18:12:50 +0100 Subject: [PATCH 2/5] Move Zip read benchmarks below RLE --- benches/read.rs | 59 ++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/benches/read.rs b/benches/read.rs index b5938f2a..01dfbcb2 100644 --- a/benches/read.rs +++ b/benches/read.rs @@ -43,34 +43,39 @@ fn read_single_image_uncompressed_rgba(bench: &mut Bencher) { }) } -/// Read with multi-core zip decompression -fn read_single_image_zips_rgba(bench: &mut Bencher) { - let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); +/// Read with multi-core RLE decompression +fn read_single_image_rle_all_channels(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); bench.iter(||{ bencher::black_box(&mut file); let image = exr::prelude::read() - .no_deep_data().largest_resolution_level() - .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) - .all_layers().all_attributes() + .no_deep_data() + .largest_resolution_level() + .all_channels() + .all_layers() + .all_attributes() .from_buffered(Cursor::new(file.as_slice())).unwrap(); bencher::black_box(image); }) } -/// Read without multi-core ZIP decompression -fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { - let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); +/// Read without multi-core RLE decompression +fn read_single_image_rle_non_parallel_all_channels(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); bench.iter(||{ bencher::black_box(&mut file); + // copied from `read_all_flat_layers_from_file` and added `.non_parallel()` let image = exr::prelude::read() - .no_deep_data().largest_resolution_level() - .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) - .all_layers().all_attributes() + .no_deep_data() + .largest_resolution_level() + .all_channels() + .all_layers() + .all_attributes() .non_parallel() .from_buffered(Cursor::new(file.as_slice())).unwrap(); @@ -78,40 +83,34 @@ fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { }) } -/// Read with multi-core RLE decompression -fn read_single_image_rle_all_channels(bench: &mut Bencher) { - let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); +/// Read with multi-core zip decompression +fn read_single_image_zips_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); bench.iter(||{ bencher::black_box(&mut file); - // copied from `read_all_flat_layers_from_file` and added `.non_parallel()` let image = exr::prelude::read() - .no_deep_data() - .largest_resolution_level() - .all_channels() - .all_layers() - .all_attributes() + .no_deep_data().largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers().all_attributes() .from_buffered(Cursor::new(file.as_slice())).unwrap(); bencher::black_box(image); }) } -/// Read without multi-core RLE decompression -fn read_single_image_rle_non_parallel_all_channels(bench: &mut Bencher) { - let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); +/// Read without multi-core ZIP decompression +fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); bench.iter(||{ bencher::black_box(&mut file); - // copied from `read_all_flat_layers_from_file` and added `.non_parallel()` let image = exr::prelude::read() - .no_deep_data() - .largest_resolution_level() - .all_channels() - .all_layers() - .all_attributes() + .no_deep_data().largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers().all_attributes() .non_parallel() .from_buffered(Cursor::new(file.as_slice())).unwrap(); From 8e193604d8c84cff66e0f0b72431a5d4d435e7a0 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 2 Jan 2023 18:14:17 +0100 Subject: [PATCH 3/5] Add RLE RGBA benchmarks --- benches/read.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/benches/read.rs b/benches/read.rs index 01dfbcb2..aa59b524 100644 --- a/benches/read.rs +++ b/benches/read.rs @@ -83,6 +83,46 @@ fn read_single_image_rle_non_parallel_all_channels(bench: &mut Bencher) { }) } +/// Read with multi-core RLE decompression +fn read_single_image_rle_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); + + bench.iter(||{ + bencher::black_box(&mut file); + + let image = exr::prelude::read() + .no_deep_data() + .largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers() + .all_attributes() + .from_buffered(Cursor::new(file.as_slice())).unwrap(); + + bencher::black_box(image); + }) +} + +/// Read without multi-core RLE decompression +fn read_single_image_rle_non_parallel_rgba(bench: &mut Bencher) { + let mut file = fs::read("tests/images/valid/custom/crowskull/crow_rle.exr").unwrap(); + + bench.iter(||{ + bencher::black_box(&mut file); + + // copied from `read_all_flat_layers_from_file` and added `.non_parallel()` + let image = exr::prelude::read() + .no_deep_data() + .largest_resolution_level() + .rgba_channels(PixelVec::<(f32,f32,f32,f32)>::constructor, PixelVec::set_pixel) + .all_layers() + .all_attributes() + .non_parallel() + .from_buffered(Cursor::new(file.as_slice())).unwrap(); + + bencher::black_box(image); + }) +} + /// Read with multi-core zip decompression fn read_single_image_zips_rgba(bench: &mut Bencher) { let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); From 73770a3ce8fd838b28643f6d95d4bb1348533621 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 2 Jan 2023 18:17:52 +0100 Subject: [PATCH 4/5] Rename benchmarks for consistency and sort the list --- benches/read.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/benches/read.rs b/benches/read.rs index aa59b524..f01266f2 100644 --- a/benches/read.rs +++ b/benches/read.rs @@ -141,7 +141,7 @@ fn read_single_image_zips_rgba(bench: &mut Bencher) { } /// Read without multi-core ZIP decompression -fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { +fn read_single_image_zips_non_parallel_rgba(bench: &mut Bencher) { let mut file = fs::read("tests/images/valid/custom/crowskull/crow_zips.exr").unwrap(); bench.iter(||{ @@ -159,12 +159,14 @@ fn read_single_image_non_parallel_zips_rgba(bench: &mut Bencher) { } benchmark_group!(read, + read_single_image_rle_all_channels, + read_single_image_rle_non_parallel_all_channels, + read_single_image_rle_non_parallel_rgba, + read_single_image_rle_rgba, read_single_image_uncompressed_non_parallel_rgba, read_single_image_uncompressed_rgba, + read_single_image_zips_non_parallel_rgba, read_single_image_zips_rgba, - read_single_image_rle_all_channels, - read_single_image_rle_non_parallel_all_channels, - read_single_image_non_parallel_zips_rgba ); benchmark_main!(read); \ No newline at end of file From 5d084f8b07f8800c574f9b351173d3740581afaa Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Mon, 2 Jan 2023 18:20:40 +0100 Subject: [PATCH 5/5] Saner benchmarking order --- benches/read.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/benches/read.rs b/benches/read.rs index f01266f2..634f16e1 100644 --- a/benches/read.rs +++ b/benches/read.rs @@ -159,14 +159,14 @@ fn read_single_image_zips_non_parallel_rgba(bench: &mut Bencher) { } benchmark_group!(read, + read_single_image_uncompressed_rgba, + read_single_image_uncompressed_non_parallel_rgba, + read_single_image_rle_rgba, + read_single_image_rle_non_parallel_rgba, read_single_image_rle_all_channels, read_single_image_rle_non_parallel_all_channels, - read_single_image_rle_non_parallel_rgba, - read_single_image_rle_rgba, - read_single_image_uncompressed_non_parallel_rgba, - read_single_image_uncompressed_rgba, - read_single_image_zips_non_parallel_rgba, read_single_image_zips_rgba, + read_single_image_zips_non_parallel_rgba, ); benchmark_main!(read); \ No newline at end of file