benchmarks comparing the rust image processing ecosystem
add blur benchmark
bendn 2023-11-06
parent 21b4c3c · commit 504dc6c
-rw-r--r--.gitignore1
-rw-r--r--Cargo.toml15
-rw-r--r--README.md13
-rw-r--r--benches/blur.rs56
-rw-r--r--blur.svg1
-rw-r--r--small_data.pngbin0 -> 2835944 bytes
6 files changed, 79 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 0cf4a1b..c97cb53 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ data.imgbuf
*.dat
*.plot
Cargo.lock
+small_data.imgbuf
diff --git a/Cargo.toml b/Cargo.toml
index 2fd7db6..0adcf69 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,11 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-fimg = { version = "0.4.23", features = [
- "text",
- "blur",
- "scale",
-], git = "https://github.com/bend-n/fimg" }
+blud = "0.0.0"
+blurslice = "0.1.0"
+fimg = { version = "0.4.23", features = ["text", "blur", "scale"] }
iai = { git = "https://github.com/bend-n/iai", version = "0.1.1" }
image = { version = "0.24.7", default-features = false, features = ["png"] }
imageproc = { version = "0.23.0", default-features = false }
@@ -18,6 +16,9 @@ resize = { version = "0.8.2", default-features = false, features = ["std"] }
rgb = "0.8.37"
umath = "0.0.7"
+[patch.crates-io]
+fimg = { git = "https://github.com/bend-n/fimg" }
+
[[bench]]
harness = false
name = "affine"
@@ -29,3 +30,7 @@ name = "resizing"
[[bench]]
harness = false
name = "drawing"
+
+[[bench]]
+harness = false
+name = "blur"
diff --git a/README.md b/README.md
index f734349..034f18b 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,19 @@
-## a series of benchmarks, comparing [imageproc](https://crates.io/crates/imageproc) and [fimg](https://crates.io/crates/fimg)
+## a series of benchmarks, comparing different image processing crates
+
+including:
+- [fimg](https://crates.io/crates/fimg)
+- [imageproc](https://crates.io/crates/imageproc)
+- [image](https://crates.io/crates/image)
+- [blud](https://crates.io/crates/blud)
+- [blurslice](https://crates.io/crates/blurslice)
+- [resize](https://crates.io/crates/resize)
![](./affine.svg)
![](./resizing.svg)
![](./drawing.svg)
+![](./blur.svg)
### how to run benchmarks
-step 1: unhew. `cargo install --git https://github.com/bend-n/hew && hew data.png data.imgbuf`
+step 1: unhew. `cargo install --git https://github.com/bend-n/hew && hew data.png data.imgbuf && hew small_data.png small_data.imgbuf`
step 2: run. `cargo bench` \ No newline at end of file
diff --git a/benches/blur.rs b/benches/blur.rs
new file mode 100644
index 0000000..4444334
--- /dev/null
+++ b/benches/blur.rs
@@ -0,0 +1,56 @@
+use fimg::Image;
+use image::RgbImage;
+
+const SIZE: u32 = 1356;
+
+pub fn imageproc() {
+ iai::black_box(&imageproc::filter::gaussian_blur_f32(
+ &RgbImage::from_raw(
+ SIZE,
+ SIZE,
+ iai::black_box(include_bytes!("../small_data.imgbuf").to_vec()),
+ )
+ .unwrap(),
+ 15.0,
+ ));
+}
+
+pub fn image() {
+ iai::black_box(&image::imageops::blur(
+ &RgbImage::from_raw(
+ SIZE,
+ SIZE,
+ iai::black_box(include_bytes!("../small_data.imgbuf").to_vec()),
+ )
+ .unwrap(),
+ 15.0,
+ ));
+}
+
+pub fn blurslice() {
+ let mut data = iai::black_box(include_bytes!("../small_data.imgbuf").to_vec());
+ blurslice::gaussian_blur_bytes::<3>(&mut data, SIZE as usize, SIZE as usize, 15.0).unwrap();
+ iai::black_box(&data);
+}
+
+pub fn blud() {
+ let mut i = Image::<_, 3>::build(SIZE, SIZE).buf(iai::black_box(
+ include_bytes!("../small_data.imgbuf")
+ .to_vec()
+ .into_boxed_slice(),
+ ));
+ blud::blur(&mut i, unsafe { umath::FF32::new(15.0) });
+ iai::black_box(&i);
+}
+
+pub fn fimg() {
+ let mut i = Image::<_, 3>::build(SIZE, SIZE).buf(iai::black_box(
+ include_bytes!("../small_data.imgbuf")
+ .to_vec()
+ .into_boxed_slice(),
+ ));
+ i.blur(30);
+ iai::black_box(&i);
+}
+
+iai::main!(blud, imageproc, fimg, image);
diff --git a/blur.svg b/blur.svg
new file mode 100644
index 0000000..5481922
--- /dev/null
+++ b/blur.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="400" height="480"><path fill="#fff" d="M0 0h400v480H0z"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 444h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 447.9)"><tspan> 0</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 396.38h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 400.28)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 348.75h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 352.65)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 301.13h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 305.03)"><tspan> 3x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 253.5h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 257.4)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 205.88h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 209.78)"><tspan> 5x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 158.26h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 162.16)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 110.63h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 114.53)"><tspan> 7x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 63.01h9m276.51 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(80.92 66.91)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M89.31 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(89.31 465.9)"><tspan> </tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M160.69 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(160.69 465.9)"><tspan> </tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M232.07 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(232.07 465.9)"><tspan> </tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M303.44 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(303.44 465.9)"><tspan> </tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M374.82 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(374.82 465.9)"><tspan> </tspan></text></g><path fill="none" stroke="#000" d="M89.31 63.01V444h285.51V63.01H89.31Z" color="#000"/><text color="#000" font-family="Arial" font-size="12" text-anchor="middle" transform="rotate(-90 136.345 117.165)"><tspan>cycles</tspan></text><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(307.09 84.91)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M315.48 85.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M315.48 85.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M174.96 444h28.56v-32.14h-28.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M174.96 444v-32.13h28.55V444h-28.55Z"/></g><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(307.09 102.91)"><tspan>imgproc</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M315.48 103.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M315.48 103.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M203.51 444h28.57V136.74h-28.57z" shape-rendering="crispEdges"/><path stroke="#000" d="M203.51 444V136.75h28.56V444h-28.56Z"/></g><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(307.09 120.91)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#56B4E9" stroke="none" d="M315.48 121.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M315.48 121.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#56B4E9" stroke="none" d="M232.07 444h28.56V96.66h-28.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M232.07 444V96.67h28.55V444h-28.55Z"/></g><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(307.09 138.91)"><tspan>blud</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#E69F00" stroke="none" d="M315.48 139.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M315.48 139.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#E69F00" stroke="none" d="M260.62 444h28.56v-32.28h-28.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M260.62 444v-32.27h28.55V444h-28.55Z"/></g><path fill="none" stroke="#000" d="M89.31 63.01V444h285.51V63.01H89.31Z" color="#000"/><text color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(232.06 32.86)"><tspan>gaussian blur</tspan></text></svg> \ No newline at end of file
diff --git a/small_data.png b/small_data.png
new file mode 100644
index 0000000..8d26804
--- /dev/null
+++ b/small_data.png
Binary files differ