| 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 LABS: Vec<lab::Lab> = { |
| 14 | let rand_seed = [0u8; 32]; |
| 15 | let rng: rand::rngs::StdRng = rand::SeedableRng::from_seed(rand_seed); |
| 16 | let labs: Vec<[f32; 8]> = rng.sample_iter(&Standard).take(512).collect(); |
| 17 | labs.iter() |
| 18 | .map(|lab| lab::Lab { |
| 19 | l: lab[0], |
| 20 | a: lab[1], |
| 21 | b: lab[2], |
| 22 | }) |
| 23 | .collect() |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | fn labs_to_rgbs(c: &mut Criterion) { |
| 28 | c.bench_function("[Lab] -> [RGB]", move |b| { |
| 29 | b.iter(|| lab::__scalar::labs_to_rgbs(&LABS)) |
| 30 | }); |
| 31 | } |
| 32 | |
| 33 | fn labs_to_rgb_bytes(c: &mut Criterion) { |
| 34 | c.bench_function("[Lab] -> [u8]", move |b| { |
| 35 | b.iter(|| lab::__scalar::labs_to_rgb_bytes(&LABS)) |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | fn labs_to_rgbs_simd(c: &mut Criterion) { |
| 40 | c.bench_function("[Lab] -> [RGB] (simd)", move |b| { |
| 41 | b.iter(|| lab::labs_to_rgbs(&LABS)) |
| 42 | }); |
| 43 | } |
| 44 | |
| 45 | fn labs_to_rgb_bytes_simd(c: &mut Criterion) { |
| 46 | c.bench_function("[Lab] -> [u8] (simd)", move |b| { |
| 47 | b.iter(|| lab::labs_to_rgb_bytes(&LABS)) |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | criterion_group!( |
| 52 | benches, |
| 53 | labs_to_rgbs, |
| 54 | labs_to_rgb_bytes, |
| 55 | labs_to_rgbs_simd, |
| 56 | labs_to_rgb_bytes_simd |
| 57 | ); |
| 58 | criterion_main!(benches); |