summaryrefslogtreecommitdiffstats
path: root/third_party/rust/image/benches
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/image/benches')
-rw-r--r--third_party/rust/image/benches/README.md6
-rw-r--r--third_party/rust/image/benches/encode_jpeg.rs30
-rw-r--r--third_party/rust/image/benches/load.rs84
3 files changed, 120 insertions, 0 deletions
diff --git a/third_party/rust/image/benches/README.md b/third_party/rust/image/benches/README.md
new file mode 100644
index 0000000000..9516f2cb62
--- /dev/null
+++ b/third_party/rust/image/benches/README.md
@@ -0,0 +1,6 @@
+# Getting started with benchmarking
+
+To run the benchmarks you need a nightly rust toolchain.
+Then you launch it with
+
+ cargo +nightly bench --features=benchmarks
diff --git a/third_party/rust/image/benches/encode_jpeg.rs b/third_party/rust/image/benches/encode_jpeg.rs
new file mode 100644
index 0000000000..33e2586111
--- /dev/null
+++ b/third_party/rust/image/benches/encode_jpeg.rs
@@ -0,0 +1,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);
+}
diff --git a/third_party/rust/image/benches/load.rs b/third_party/rust/image/benches/load.rs
new file mode 100644
index 0000000000..4b2d79e3e1
--- /dev/null
+++ b/third_party/rust/image/benches/load.rs
@@ -0,0 +1,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");
+}