@@ -10,98 +10,163 @@ use std::io::Cursor;
1010use exr:: image:: pixel_vec:: PixelVec ;
1111
1212/// Read uncompressed (always single core)
13- fn read_single_image_uncompressed_rgba ( bench : & mut Bencher ) {
13+ fn read_single_image_uncompressed_non_parallel_rgba ( bench : & mut Bencher ) {
14+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_uncompressed.exr" ) . unwrap ( ) ;
1415 bench. iter ( ||{
15- let path = "tests/images/valid/custom/crowskull/crow_uncompressed.exr" ;
16+ bencher :: black_box ( & mut file ) ;
1617
17- let image = read_all_rgba_layers_from_file (
18- path, PixelVec :: < ( f16 , f16 , f16 , f16 ) > :: constructor, PixelVec :: set_pixel
19- ) . unwrap ( ) ;
18+ let image = exr:: prelude:: read ( )
19+ . no_deep_data ( ) . largest_resolution_level ( )
20+ . rgba_channels ( PixelVec :: < ( f32 , f32 , f32 , f32 ) > :: constructor, PixelVec :: set_pixel)
21+ . all_layers ( ) . all_attributes ( )
22+ . non_parallel ( )
23+ . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
2024
2125 bencher:: black_box ( image) ;
2226 } )
2327}
2428
2529/// Read from in-memory in parallel
26- fn read_single_image_uncompressed_from_buffer_rgba ( bench : & mut Bencher ) {
27- let file = fs:: read ( "tests/images/valid/custom/crowskull/crow_uncompressed.exr" ) . unwrap ( ) ;
30+ fn read_single_image_uncompressed_rgba ( bench : & mut Bencher ) {
31+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_uncompressed.exr" ) . unwrap ( ) ;
2832
2933 bench. iter ( ||{
34+ bencher:: black_box ( & mut file) ;
35+
3036 let image = exr:: prelude:: read ( )
3137 . no_deep_data ( ) . largest_resolution_level ( )
32- . rgba_channels ( PixelVec :: < ( f16 , f16 , f16 , f16 ) > :: constructor, PixelVec :: set_pixel)
38+ . rgba_channels ( PixelVec :: < ( f32 , f32 , f32 , f32 ) > :: constructor, PixelVec :: set_pixel)
3339 . all_layers ( ) . all_attributes ( )
3440 . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
3541
3642 bencher:: black_box ( image) ;
3743 } )
3844}
3945
40- /// Read with multi-core zip decompression
41- fn read_single_image_zips_rgba ( bench : & mut Bencher ) {
46+ /// Read with multi-core RLE decompression
47+ fn read_single_image_rle_all_channels ( bench : & mut Bencher ) {
48+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_rle.exr" ) . unwrap ( ) ;
49+
50+ bench. iter ( ||{
51+ bencher:: black_box ( & mut file) ;
52+
53+ let image = exr:: prelude:: read ( )
54+ . no_deep_data ( )
55+ . largest_resolution_level ( )
56+ . all_channels ( )
57+ . all_layers ( )
58+ . all_attributes ( )
59+ . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
60+
61+ bencher:: black_box ( image) ;
62+ } )
63+ }
64+
65+ /// Read without multi-core RLE decompression
66+ fn read_single_image_rle_non_parallel_all_channels ( bench : & mut Bencher ) {
67+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_rle.exr" ) . unwrap ( ) ;
68+
4269 bench. iter ( ||{
43- let path = "tests/images/valid/custom/crowskull/crow_zips.exr" ;
70+ bencher :: black_box ( & mut file ) ;
4471
45- let image = read_all_rgba_layers_from_file (
46- path, PixelVec :: < ( f16 , f16 , f16 , f16 ) > :: constructor, PixelVec :: set_pixel
47- ) . unwrap ( ) ;
72+ // copied from `read_all_flat_layers_from_file` and added `.non_parallel()`
73+ let image = exr:: prelude:: read ( )
74+ . no_deep_data ( )
75+ . largest_resolution_level ( )
76+ . all_channels ( )
77+ . all_layers ( )
78+ . all_attributes ( )
79+ . non_parallel ( )
80+ . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
4881
4982 bencher:: black_box ( image) ;
5083 } )
5184}
5285
5386/// Read with multi-core RLE decompression
54- fn read_single_image_rle_all_channels ( bench : & mut Bencher ) {
87+ fn read_single_image_rle_rgba ( bench : & mut Bencher ) {
88+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_rle.exr" ) . unwrap ( ) ;
89+
5590 bench. iter ( ||{
56- let path = "tests/images/valid/custom/crowskull/crow_rle.exr" ;
91+ bencher:: black_box ( & mut file) ;
92+
93+ let image = exr:: prelude:: read ( )
94+ . no_deep_data ( )
95+ . largest_resolution_level ( )
96+ . rgba_channels ( PixelVec :: < ( f32 , f32 , f32 , f32 ) > :: constructor, PixelVec :: set_pixel)
97+ . all_layers ( )
98+ . all_attributes ( )
99+ . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
57100
58- let image = read_all_flat_layers_from_file ( path) . unwrap ( ) ;
59101 bencher:: black_box ( image) ;
60102 } )
61103}
62104
63105/// Read without multi-core RLE decompression
64- fn read_single_image_rle_non_parallel_all_channels ( bench : & mut Bencher ) {
106+ fn read_single_image_rle_non_parallel_rgba ( bench : & mut Bencher ) {
107+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_rle.exr" ) . unwrap ( ) ;
108+
65109 bench. iter ( ||{
66- let path = "tests/images/valid/custom/crowskull/crow_rle.exr" ;
110+ bencher :: black_box ( & mut file ) ;
67111
68112 // copied from `read_all_flat_layers_from_file` and added `.non_parallel()`
69113 let image = exr:: prelude:: read ( )
70114 . no_deep_data ( )
71115 . largest_resolution_level ( )
72- . all_channels ( )
116+ . rgba_channels ( PixelVec :: < ( f32 , f32 , f32 , f32 ) > :: constructor , PixelVec :: set_pixel )
73117 . all_layers ( )
74118 . all_attributes ( )
75119 . non_parallel ( )
76- . from_file ( path) . unwrap ( ) ;
120+ . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
121+
122+ bencher:: black_box ( image) ;
123+ } )
124+ }
125+
126+ /// Read with multi-core zip decompression
127+ fn read_single_image_zips_rgba ( bench : & mut Bencher ) {
128+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_zips.exr" ) . unwrap ( ) ;
129+
130+ bench. iter ( ||{
131+ bencher:: black_box ( & mut file) ;
132+
133+ let image = exr:: prelude:: read ( )
134+ . no_deep_data ( ) . largest_resolution_level ( )
135+ . rgba_channels ( PixelVec :: < ( f32 , f32 , f32 , f32 ) > :: constructor, PixelVec :: set_pixel)
136+ . all_layers ( ) . all_attributes ( )
137+ . from_buffered ( Cursor :: new ( file. as_slice ( ) ) ) . unwrap ( ) ;
138+
77139 bencher:: black_box ( image) ;
78140 } )
79141}
80142
81143/// Read without multi-core ZIP decompression
82- fn read_single_image_non_parallel_zips_rgba ( bench : & mut Bencher ) {
144+ fn read_single_image_zips_non_parallel_rgba ( bench : & mut Bencher ) {
145+ let mut file = fs:: read ( "tests/images/valid/custom/crowskull/crow_zips.exr" ) . unwrap ( ) ;
146+
83147 bench. iter ( ||{
84- let path = "tests/images/valid/custom/crowskull/crow_zips.exr" ;
148+ bencher :: black_box ( & mut file ) ;
85149
86150 let image = exr:: prelude:: read ( )
87151 . no_deep_data ( ) . largest_resolution_level ( )
88- . rgba_channels ( PixelVec :: < ( f16 , f16 , f16 , f16 ) > :: constructor, PixelVec :: set_pixel)
152+ . rgba_channels ( PixelVec :: < ( f32 , f32 , f32 , f32 ) > :: constructor, PixelVec :: set_pixel)
89153 . all_layers ( ) . all_attributes ( )
90154 . non_parallel ( )
91- . from_file ( path ) . unwrap ( ) ;
155+ . from_buffered ( Cursor :: new ( file . as_slice ( ) ) ) . unwrap ( ) ;
92156
93157 bencher:: black_box ( image) ;
94158 } )
95159}
96160
97-
98161benchmark_group ! ( read,
99- read_single_image_uncompressed_from_buffer_rgba,
100162 read_single_image_uncompressed_rgba,
101- read_single_image_zips_rgba,
163+ read_single_image_uncompressed_non_parallel_rgba,
164+ read_single_image_rle_rgba,
165+ read_single_image_rle_non_parallel_rgba,
102166 read_single_image_rle_all_channels,
103167 read_single_image_rle_non_parallel_all_channels,
104- read_single_image_non_parallel_zips_rgba
168+ read_single_image_zips_rgba,
169+ read_single_image_zips_non_parallel_rgba,
105170) ;
106171
107172benchmark_main ! ( read) ;
0 commit comments