aboutsummaryrefslogtreecommitdiffstats
path: root/components/pixels/benches.rs
blob: 50002851d4545be1f41261459a612c89ed8452a6 (plain) (blame)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use criterion::*;

fn create_data(number_of_pixels: usize) -> Vec<u8> {
    (0..=number_of_pixels)
        .map(|i| {
            let i = (i % 255) as u8;
            [i, i, i, i]
        })
        .flatten()
        .collect()
}

fn bench(c: &mut Criterion) {
    let data = create_data(1_000_000);

    c.bench_function("unmultiply_inplace", move |b| {
        b.iter_batched(
            || data.clone(),
            |mut data| pixels::unmultiply_inplace(&mut data),
            BatchSize::SmallInput,
        )
    });
}

criterion_group!(benches, bench);
criterion_main!(benches);