Debian Codegraph @

benches/rgb_to_lab.rs

raw symbols SCIP
1 #[macro_use]
2 extern crate criterion;
3 #[macro_use]
4 extern crate lazy_static;
5 extern crate lab;
6 extern crate rand;
7
8 use criterion::Criterion;
9 use rand::distributions::Standard;
10 use rand::Rng;
11
12 lazy_static! {
13 static ref RGBS: Vec<[u8; 3]> = {
14 let rand_seed = [0u8; 32];
15 let rng: rand::rngs::StdRng = rand::SeedableRng::from_seed(rand_seed);
16 rng.sample_iter(&Standard).take(512).collect()
17 };
18 static ref RGBS_FLAT: Vec<u8> =
19 RGBS.iter()
20 .fold(Vec::with_capacity(RGBS.len() * 3), |mut acc, rgb| {
21 acc.extend_from_slice(rgb);
22 acc
23 });
24 }
25
26 fn rgbs_to_labs(c: &mut Criterion) {
27 c.bench_function("[RGB] -> [Lab]", move |b| {
28 b.iter(|| lab::__scalar::rgbs_to_labs(&RGBS))
29 });
30 }
31
32 fn rgb_bytes_to_labs(c: &mut Criterion) {
33 c.bench_function("[u8] -> [Lab]", move |b| {
34 b.iter(|| lab::__scalar::rgb_bytes_to_labs(&RGBS_FLAT))
35 });
36 }
37
38 fn rgbs_to_labs_simd(c: &mut Criterion) {
39 c.bench_function("[RGB] -> [Lab] (simd)", move |b| {
40 b.iter(|| lab::rgbs_to_labs(&RGBS))
41 });
42 }
43
44 fn rgb_bytes_to_labs_simd(c: &mut Criterion) {
45 c.bench_function("[u8] -> [Lab] (simd)", move |b| {
46 b.iter(|| lab::rgb_bytes_to_labs(&RGBS_FLAT))
47 });
48 }
49
50 criterion_group!(
51 benches,
52 rgbs_to_labs,
53 rgb_bytes_to_labs,
54 rgbs_to_labs_simd,
55 rgb_bytes_to_labs_simd
56 );
57 criterion_main!(benches);