benchmarks comparing the rust image processing ecosystem
remove allocations
bendn 2023-11-08
parent d0d075e · commit 05e9dd8
-rw-r--r--benches/resizing.rs20
-rw-r--r--resizing.svg2
2 files changed, 12 insertions, 10 deletions
diff --git a/benches/resizing.rs b/benches/resizing.rs
index 18ad709..8facfc9 100644
--- a/benches/resizing.rs
+++ b/benches/resizing.rs
@@ -9,10 +9,12 @@ macro_rules! scale_opencv {
($name:ident => { scale($alg:literal) }) => {
fn $name() {
opencv::core::set_num_threads(1).unwrap();
- let mut data = iai::black_box(include_bytes!("../data.imgbuf").to_vec())
- .array_chunks::<3>()
- .flat_map(|&[r, g, b]| [b, g, r])
- .collect::<Vec<_>>();
+ let mut data = iai::black_box(
+ include_bytes!("../data.imgbuf")
+ .array_chunks::<3>()
+ .flat_map(|&[r, g, b]| [b, g, r])
+ .collect::<Vec<_>>(),
+ );
let mut o = unsafe { Mat::new_rows_cols(SIZE as i32, SIZE as i32, CV_8UC3).unwrap() };
opencv::imgproc::resize(
&unsafe {
@@ -46,9 +48,9 @@ macro_rules! scale_fimg {
fn $name() {
#[allow(unused_mut)]
let mut img = Image::<_, 3>::build(SIZE, SIZE)
- .buf(iai::black_box(include_bytes!("../data.imgbuf").to_vec()));
+ .buf(&iai::black_box(include_bytes!("../data.imgbuf"))[..]);
img.scale::<fimg::scale::$alg>(TO, TO);
- iai::black_box(img);
+ iai::black_box(&img);
}
};
}
@@ -57,7 +59,7 @@ macro_rules! scale_resize {
($name:ident => { scale($alg: ident) }) => {
fn $name() {
use rgb::FromSlice;
- let src = iai::black_box(include_bytes!("../data.imgbuf").to_vec());
+ let src = iai::black_box(include_bytes!("../data.imgbuf").as_rgb());
let mut dst = vec![0; TO as usize * TO as usize * 3];
resize::new(
SIZE as usize,
@@ -68,7 +70,7 @@ macro_rules! scale_resize {
resize::Type::$alg,
)
.unwrap()
- .resize(src.as_rgb(), dst.as_rgb_mut())
+ .resize(src, dst.as_rgb_mut())
.unwrap();
}
};
@@ -116,5 +118,5 @@ iai::main!(
bicubic_fimg,
bicubic_img,
bicubic_resize,
- bicubic_opencv
+ bicubic_opencv,
);
diff --git a/resizing.svg b/resizing.svg
index faa65ea..2038e40 100644
--- a/resizing.svg
+++ b/resizing.svg
@@ -1 +1 @@
-<svg xmlns="http://www.w3.org/2000/svg" width="480" height="480"><path fill="#0d1117" d="M0 0h480v480H0z"/><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 444h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 444h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 447.9)"><tspan> 0</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 380.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 380.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 384.4)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 317h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 317h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 320.9)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 253.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 253.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 257.4)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 190.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 190.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 193.91)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 126.51h205.47m126.48 0h8.39" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 126.51h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 130.41)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 63.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 63.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 66.91)"><tspan> 1.2x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M199.57 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(199.57 465.9)"><tspan>lanczos3</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M284.65 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(284.65 465.9)"><tspan>bicubic</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M369.74 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(369.74 465.9)"><tspan>nearest</tspan></text></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="rotate(-90 137.32 116.19)"><tspan>cycles</tspan></text><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 87.06)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M388.48 87.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 87.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M165.53 444h17.03v-55.4h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M165.53 444v-55.39h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M250.62 444h17.02v-45.11h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M250.62 444v-45.1h17.01V444h-17.01Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M335.7 444h17.03v-8.53H335.7z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M335.7 444v-8.52h17.02V444H335.7Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 108.06)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M388.48 108.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 108.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M182.55 444h17.03V88.59h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M182.55 444V88.6h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M267.63 444h17.03V181.64h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M267.63 444V181.65h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M352.72 444h17.03v-99.47h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M352.72 444v-99.46h17.02V444h-17.02Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 129.06)"><tspan>opencv</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M388.48 129.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 129.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M199.57 444h17.02V272.47h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M199.57 444V272.48h17.01V444h-17.01Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M284.65 444h17.03v-52.33h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M284.65 444v-52.32h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M369.74 444h17.02v-28.35h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M369.74 444v-28.34h17.01V444h-17.01Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 150.06)"><tspan>resize</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M388.48 150.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 150.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M216.58 444h17.03V200.98h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M216.58 444V200.99h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M301.67 444h17.02V269.03h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M301.67 444V269.04h17.01V444h-17.01Z"/></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(284.65 32.86)"><tspan>resizing</tspan></text></svg> \ No newline at end of file
+<svg xmlns="http://www.w3.org/2000/svg" width="480" height="480"><path fill="#0d1117" d="M0 0h480v480H0z"/><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 444h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 444h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 447.9)"><tspan> 0</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 380.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 380.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 384.4)"><tspan> 2x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 317h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 317h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 320.9)"><tspan> 4x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 253.5h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 253.5h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 257.4)"><tspan> 6x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 190.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 190.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 193.91)"><tspan> 8x10</tspan><tspan dy="-6" font-size="9.6">9</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 126.51h205.47m126.48 0h8.39" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 126.51h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 130.41)"><tspan> 1x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><path fill="none" stroke="#1F2430" stroke-dasharray="5,8" stroke-width="2" d="M114.48 63.01h340.34" class="gridline" color="#000"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M114.48 63.01h9m331.34 0h-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 66.91)"><tspan> 1.2x10</tspan><tspan dy="-6" font-size="9.6">10</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M199.57 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(199.57 465.9)"><tspan>lanczos</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M284.65 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(284.65 465.9)"><tspan>bicubic</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#E6EDF3" d="M369.74 444v-9"/><text fill="#E6EDF3" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(369.74 465.9)"><tspan>nearest</tspan></text></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="rotate(-90 137.32 116.19)"><tspan>cycles</tspan></text><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 87.06)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M388.48 87.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 87.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M165.53 444h17.03v-51.63h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M165.53 444v-51.62h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M250.62 444h17.02v-41.35h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M250.62 444v-41.34h17.01V444h-17.01Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#73D0FF" stroke="none" d="M335.7 444h17.03v-4.77H335.7z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M335.7 444v-4.76h17.02V444H335.7Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 108.06)"><tspan>image</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M388.48 108.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 108.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M182.55 444h17.03V88.58h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M182.55 444V88.59h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M267.63 444h17.03V181.64h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M267.63 444V181.65h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#FFD173" stroke="none" d="M352.72 444h17.03v-99.48h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M352.72 444v-99.47h17.02V444h-17.02Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 129.06)"><tspan>opencv</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M388.48 129.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 129.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M199.57 444h17.02V283.71h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M199.57 444V283.72h17.01V444h-17.01Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M284.65 444h17.03v-41.09h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M284.65 444v-41.08h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#D5FF80" stroke="none" d="M369.74 444h17.02v-17.11h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M369.74 444v-17.1h17.01V444h-17.01Z"/></g><text fill="#E6EDF3" stroke-width="2" color="#000" font-family="Verdana" font-size="14" text-anchor="end" transform="translate(378.69 150.06)"><tspan>resize</tspan></text><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M388.48 150.76h48.16v-10.5h-48.16z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M388.48 150.76h48.16v-10.5h-48.16v10.5Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M216.58 444h17.03V207.54h-17.03z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M216.58 444V207.55h17.02V444h-17.02Z"/></g><g fill="none" stroke="currentColor" stroke-width="2" color="#000"><path fill="#F27983" stroke="none" d="M301.67 444h17.02V274.65h-17.02z" shape-rendering="crispEdges"/><path stroke="#1A1F29" d="M301.67 444V274.66h17.01V444h-17.01Z"/></g><path fill="none" stroke="#E6EDF3" d="M114.48 63.01V444h340.34V63.01H114.48Z" color="#000"/><text fill="#E6EDF3" color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(284.65 32.86)"><tspan>resizing</tspan></text></svg> \ No newline at end of file