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
|
#![cfg(feature = "benchmarks")]
#![feature(test)]
extern crate image;
extern crate test;
use image::ImageFormat;
use std::io::Read;
use std::{fs, path};
struct BenchDef<'a> {
dir: &'a [&'a str],
format: ImageFormat,
}
const IMAGE_DIR: [&'static str; 3] = [".", "tests", "images"];
const BMP: BenchDef<'static> = BenchDef {
dir: &["bmp", "images"],
format: ImageFormat::Bmp,
};
fn bench_load(b: &mut test::Bencher, def: &BenchDef, filename: &str) {
let mut path: path::PathBuf = IMAGE_DIR.iter().collect();
for d in def.dir {
path.push(d);
}
path.push(filename);
let mut fin = fs::File::open(path).unwrap();
let mut buf = Vec::new();
fin.read_to_end(&mut buf).unwrap();
b.iter(|| {
image::load_from_memory_with_format(&buf, def.format).unwrap();
})
}
#[bench]
fn bench_load_bmp_1bit(b: &mut test::Bencher) {
bench_load(b, &BMP, "Core_1_Bit.bmp");
}
#[bench]
fn bench_load_bmp_4bit(b: &mut test::Bencher) {
bench_load(b, &BMP, "Core_4_Bit.bmp");
}
#[bench]
fn bench_load_bmp_8bit(b: &mut test::Bencher) {
bench_load(b, &BMP, "Core_8_Bit.bmp");
}
#[bench]
fn bench_load_bmp_16bit(b: &mut test::Bencher) {
bench_load(b, &BMP, "rgb16.bmp");
}
#[bench]
fn bench_load_bmp_24bit(b: &mut test::Bencher) {
bench_load(b, &BMP, "rgb24.bmp");
}
#[bench]
fn bench_load_bmp_32bit(b: &mut test::Bencher) {
bench_load(b, &BMP, "rgb32.bmp");
}
#[bench]
fn bench_load_bmp_4rle(b: &mut test::Bencher) {
bench_load(b, &BMP, "pal4rle.bmp");
}
#[bench]
fn bench_load_bmp_8rle(b: &mut test::Bencher) {
bench_load(b, &BMP, "pal8rle.bmp");
}
#[bench]
fn bench_load_bmp_16bf(b: &mut test::Bencher) {
bench_load(b, &BMP, "rgb16-565.bmp");
}
#[bench]
fn bench_load_bmp_32bf(b: &mut test::Bencher) {
bench_load(b, &BMP, "rgb32bf.bmp");
}
|