1
1
use criterion:: { black_box, criterion_group, criterion_main, Criterion , Throughput } ;
2
2
use palette:: convert:: FromColorUnclamped ;
3
3
use palette:: encoding;
4
- use palette:: { Hsl , Hsv , Hwb , LinSrgb , Srgb } ;
4
+ use palette:: { Hsl , Hsv , Hwb , IntoColor , LinSrgb , Srgb } ;
5
+
6
+ type SrgbHsv = Hsv < encoding:: Srgb > ;
7
+ type SrgbHsl = Hsl < encoding:: Srgb > ;
8
+ type SrgbHwb = Hwb < encoding:: Srgb > ;
9
+ type LinHsv = Hsv < encoding:: Linear < encoding:: Srgb > > ;
10
+ type LinHsl = Hsl < encoding:: Linear < encoding:: Srgb > > ;
11
+ type LinHwb = Hwb < encoding:: Linear < encoding:: Srgb > > ;
5
12
6
13
#[ path = "../tests/convert/data_color_mine.rs" ]
7
14
#[ allow( dead_code) ]
@@ -19,6 +26,12 @@ use data_color_mine::{load_data, ColorMine};
19
26
- xyz to rgb
20
27
- hsl to rgb
21
28
- hsv to rgb
29
+ - hsv to linear hsv
30
+ - linear hsv to hsv
31
+ - hsl to linear hsl
32
+ - linear hsl to hsl
33
+ - hwb to linear hwb
34
+ - linear hwb to hwb
22
35
- linsrgb to rgb
23
36
- rgb_u8 to linsrgb_f32
24
37
- linsrgb_f32 to rgb_u8
@@ -27,22 +40,25 @@ use data_color_mine::{load_data, ColorMine};
27
40
fn rgb_conversion ( c : & mut Criterion ) {
28
41
let mut group = c. benchmark_group ( "Rgb family" ) ;
29
42
let colormine: Vec < ColorMine > = load_data ( ) ;
30
- let rgb: Vec < Srgb > = colormine. iter ( ) . map ( |x| Srgb :: from ( x. linear_rgb ) ) . collect ( ) ;
31
- let rgb_u8: Vec < Srgb < u8 > > = rgb. iter ( ) . map ( |x| x. into_format ( ) . into ( ) ) . collect ( ) ;
43
+ let rgb_u8: Vec < Srgb < u8 > > = colormine. iter ( ) . map ( |x| x. rgb . into_format ( ) ) . collect ( ) ;
44
+
45
+ let linear_hsv: Vec < LinHsv > = colormine. iter ( ) . map ( |x| x. hsv . into_color ( ) ) . collect ( ) ;
46
+ let linear_hsl: Vec < LinHsl > = colormine. iter ( ) . map ( |x| x. hsl . into_color ( ) ) . collect ( ) ;
47
+ let linear_hwb: Vec < LinHwb > = colormine. iter ( ) . map ( |x| x. hwb . into_color ( ) ) . collect ( ) ;
32
48
33
49
group. throughput ( Throughput :: Elements ( colormine. len ( ) as u64 ) ) ;
34
50
35
- group. bench_with_input ( "rgb to linsrgb" , & rgb , |b, rgb | {
51
+ group. bench_with_input ( "rgb to linsrgb" , & colormine , |b, colormine | {
36
52
b. iter ( || {
37
- for c in rgb {
38
- black_box ( c. into_linear ( ) ) ;
53
+ for c in colormine {
54
+ black_box ( c. rgb . into_linear ( ) ) ;
39
55
}
40
56
} )
41
57
} ) ;
42
- group. bench_with_input ( "rgb to hsl" , & rgb , |b, rgb | {
58
+ group. bench_with_input ( "rgb to hsl" , & colormine , |b, colormine | {
43
59
b. iter ( || {
44
- for c in rgb {
45
- black_box ( Hsl :: from_color_unclamped ( * c ) ) ;
60
+ for c in colormine {
61
+ black_box ( Hsl :: from_color_unclamped ( c . rgb ) ) ;
46
62
}
47
63
} )
48
64
} ) ;
@@ -53,10 +69,10 @@ fn rgb_conversion(c: &mut Criterion) {
53
69
}
54
70
} )
55
71
} ) ;
56
- group. bench_with_input ( "rgb to hsv" , & rgb , |b, rgb | {
72
+ group. bench_with_input ( "rgb to hsv" , & colormine , |b, colormine | {
57
73
b. iter ( || {
58
- for c in rgb {
59
- black_box ( Hsv :: from_color_unclamped ( * c ) ) ;
74
+ for c in colormine {
75
+ black_box ( Hsv :: from_color_unclamped ( c . rgb ) ) ;
60
76
}
61
77
} )
62
78
} ) ;
@@ -102,6 +118,48 @@ fn rgb_conversion(c: &mut Criterion) {
102
118
}
103
119
} )
104
120
} ) ;
121
+ group. bench_with_input ( "hsv to linear hsv" , & colormine, |b, colormine| {
122
+ b. iter ( || {
123
+ for c in colormine {
124
+ black_box ( LinHsv :: from_color_unclamped ( c. hsv ) ) ;
125
+ }
126
+ } )
127
+ } ) ;
128
+ group. bench_with_input ( "linear hsv to hsv" , & linear_hsv, |b, linear_hsv| {
129
+ b. iter ( || {
130
+ for & c in linear_hsv {
131
+ black_box ( SrgbHsv :: from_color_unclamped ( c) ) ;
132
+ }
133
+ } )
134
+ } ) ;
135
+ group. bench_with_input ( "hsl to linear hsl" , & colormine, |b, colormine| {
136
+ b. iter ( || {
137
+ for c in colormine {
138
+ black_box ( LinHsl :: from_color_unclamped ( c. hsl ) ) ;
139
+ }
140
+ } )
141
+ } ) ;
142
+ group. bench_with_input ( "linear hsl to hsl" , & linear_hsl, |b, linear_hsl| {
143
+ b. iter ( || {
144
+ for & c in linear_hsl {
145
+ black_box ( SrgbHsl :: from_color_unclamped ( c) ) ;
146
+ }
147
+ } )
148
+ } ) ;
149
+ group. bench_with_input ( "hwb to linear hwb" , & colormine, |b, colormine| {
150
+ b. iter ( || {
151
+ for c in colormine {
152
+ black_box ( LinHwb :: from_color_unclamped ( c. hwb ) ) ;
153
+ }
154
+ } )
155
+ } ) ;
156
+ group. bench_with_input ( "linear hwb to hwb" , & linear_hwb, |b, linear_hwb| {
157
+ b. iter ( || {
158
+ for & c in linear_hwb {
159
+ black_box ( SrgbHwb :: from_color_unclamped ( c) ) ;
160
+ }
161
+ } )
162
+ } ) ;
105
163
group. bench_with_input ( "linsrgb to rgb" , & colormine, |b, colormine| {
106
164
b. iter ( || {
107
165
for c in colormine {
0 commit comments