summaryrefslogtreecommitdiffstats
path: root/third_party/rust/image/benches/encode_jpeg.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/image/benches/encode_jpeg.rs')
-rw-r--r--third_party/rust/image/benches/encode_jpeg.rs30
1 files changed, 30 insertions, 0 deletions
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);
+}