-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcie.rs
189 lines (174 loc) · 5.15 KB
/
cie.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Criterion};
use palette::{
color_difference::{Ciede2000, DeltaE},
convert::FromColorUnclamped,
};
use palette::{Lab, Lch, Xyz, Yxy};
#[path = "../../integration_tests/tests/convert/data_color_mine.rs"]
#[allow(dead_code)]
mod data_color_mine;
use data_color_mine::{load_data, ColorMine};
/* Benches the following conversions:
- xyz to lab
- lch to lab
- lab to lch
- rgb to xyz
- yxy to xyz
- lab to xyz
- xyz to yxy
*/
fn cie_conversion(c: &mut Criterion) {
let mut group = c.benchmark_group("Cie family");
let mut colormine: Vec<ColorMine<f32>> = load_data();
colormine.truncate(colormine.len() - colormine.len() % 8);
assert_eq!(
colormine.len() % 8,
0,
"number of colors must be a multiple of 8 for a fair comparison with SIMD"
);
let wide_colormine: Vec<_> = colormine
.chunks_exact(8)
.map(|chunk| {
ColorMine::<wide::f32x8>::from([
chunk[0].clone(),
chunk[1].clone(),
chunk[2].clone(),
chunk[3].clone(),
chunk[4].clone(),
chunk[5].clone(),
chunk[6].clone(),
chunk[7].clone(),
])
})
.collect();
let lab: Vec<Lab> = colormine
.iter()
.map(|x| Lab::from_color_unclamped(x.xyz))
.collect();
let lch: Vec<Lch> = colormine
.iter()
.map(|x| Lch::from_color_unclamped(x.xyz))
.collect();
group.bench_with_input("xyz to lab", &colormine, |b, colormine| {
b.iter(|| {
for c in colormine {
black_box(Lab::from_color_unclamped(c.xyz));
}
})
});
group.bench_with_input("lch to lab", &lch, |b, lch| {
b.iter(|| {
for c in lch {
black_box(Lab::from_color_unclamped(*c));
}
})
});
group.bench_with_input("lab to lch", &lab, |b, lab| {
b.iter(|| {
for c in lab {
black_box(Lch::from_color_unclamped(*c));
}
})
});
group.bench_with_input("linsrgb to xyz", &colormine, |b, colormine| {
b.iter(|| {
for c in colormine {
black_box(Xyz::from_color_unclamped(c.linear_rgb));
}
})
});
group.bench_with_input(
"linsrgb to xyz - wide f32x8",
&wide_colormine,
|b, wide_colormine| {
b.iter(|| {
for c in wide_colormine {
black_box(Xyz::from_color_unclamped(c.linear_rgb));
}
})
},
);
group.bench_with_input("yxy to xyz", &colormine, |b, colormine| {
b.iter(|| {
for c in colormine {
black_box(Xyz::from_color_unclamped(c.yxy));
}
})
});
group.bench_with_input("lab to xyz", &lab, |b, lab| {
b.iter(|| {
for c in lab {
black_box(Xyz::from_color_unclamped(*c));
}
})
});
group.bench_with_input("xyz to yxy", &colormine, |b, colormine| {
b.iter(|| {
for c in colormine {
black_box(Yxy::from_color_unclamped(c.xyz));
}
})
});
group.finish();
}
fn cie_delta_e(c: &mut Criterion) {
let mut group = c.benchmark_group("Cie delta E");
let colormine: Vec<ColorMine<f32>> = load_data();
let lab: Vec<Lab> = colormine
.iter()
.map(|x| Lab::from_color_unclamped(x.xyz))
.collect();
let lch: Vec<Lch> = colormine
.iter()
.map(|x| Lch::from_color_unclamped(x.xyz))
.collect();
group.bench_with_input("Lab delta E", &lab, |b, lab| {
b.iter(|| {
for &lhs in lab {
for &rhs in lab.iter().rev() {
black_box(lhs.delta_e(rhs));
}
}
})
});
group.bench_with_input("Lch delta E", &lch, |b, lch| {
b.iter(|| {
for &lhs in lch {
for &rhs in lch.iter().rev() {
black_box(lhs.delta_e(rhs));
}
}
})
});
group.bench_with_input("Lch delta E via Lab", &lch, |b, lch| {
b.iter(|| {
for &lhs in lch {
for &rhs in lch.iter().rev() {
black_box(
Lab::from_color_unclamped(lhs).delta_e(Lab::from_color_unclamped(rhs)),
);
}
}
})
});
group.bench_with_input("Lab CIEDE2000", &lab, |b, lab| {
b.iter(|| {
for &lhs in lab {
for &rhs in lab.iter().rev() {
black_box(lhs.difference(rhs));
}
}
})
});
group.bench_with_input("Lch CIEDE2000", &lch, |b, lch| {
b.iter(|| {
for &lhs in lch {
for &rhs in lch.iter().rev() {
black_box(lhs.difference(rhs));
}
}
})
});
}
criterion_group!(benches, cie_conversion, cie_delta_e);
criterion_main!(benches);