summaryrefslogtreecommitdiffstats
path: root/third_party/rust/image/benches/encode_jpeg.rs
blob: 33e25861117bffa4112d38bcb5d0521e59d46abf (plain)
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
#![cfg(feature = "benchmarks")]
#![feature(test)]
extern crate image;
extern crate test;

use test::Bencher;

const W: u32 = 1000;
const H: u32 = 1000;

fn run_benchmark(b: &mut Bencher, color_type: image::ColorType) {
    let mut v = Vec::with_capacity((W * H) as usize);
    let i = vec![0; (W * H) as usize];

    b.iter(|| {
        v.clear();
        let mut e = image::jpeg::JPEGEncoder::new(&mut v);
        e.encode(&i[..], W, H, color_type).unwrap();
    });
}

#[bench]
fn bench_rgb(b: &mut Bencher) {
    run_benchmark(b, image::ColorType::Rgb8);
}

#[bench]
fn bench_gray(b: &mut Bencher) {
    run_benchmark(b, image::ColorType::L8);
}