benchmarks comparing the rust image processing ecosystem
add "resize" crate
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | benches/resizing.rs | 27 | ||||
| -rw-r--r-- | resizing.svg | 2 |
3 files changed, 29 insertions, 2 deletions
@@ -14,6 +14,8 @@ fimg = { version = "0.4.23", features = [ 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 } +resize = { version = "0.8.2", default-features = false, features = ["std"] } +rgb = "0.8.37" umath = "0.0.7" [[bench]] diff --git a/benches/resizing.rs b/benches/resizing.rs index fc26eae..fb679ee 100644 --- a/benches/resizing.rs +++ b/benches/resizing.rs @@ -14,6 +14,27 @@ macro_rules! scale_fimg { }; } +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 mut dst = vec![0; TO as usize * TO as usize * 3]; + resize::new( + SIZE as usize, + SIZE as usize, + TO as usize, + TO as usize, + resize::Pixel::RGB8, + resize::Type::$alg, + ) + .unwrap() + .resize(src.as_rgb(), dst.as_rgb_mut()) + .unwrap(); + } + }; +} + macro_rules! scale_img { ($name:ident => { scale($alg: ident) }) => { fn $name() { @@ -37,14 +58,18 @@ scale_fimg!(nearest_fimg => { scale(Nearest) }); scale_img!(nearest_img => { scale(Nearest) }); scale_fimg!(lanczos_fimg => { scale(Lanczos3) }); scale_img!(lanczos_img => { scale(Lanczos3) }); +scale_resize!(lanczos_resize => { scale(Lanczos3 )}); scale_fimg!(catmull_fimg => { scale(CatmullRom) }); scale_img!(catmull_img => { scale(CatmullRom) }); +scale_resize!(catmull_resize => { scale(Catrom) }); iai::main!( nearest_fimg, nearest_img, lanczos_fimg, lanczos_img, + lanczos_resize, catmull_fimg, - catmull_img + catmull_img, + catmull_resize ); diff --git a/resizing.svg b/resizing.svg index 7f5598c..7738c10 100644 --- a/resizing.svg +++ b/resizing.svg @@ -1 +1 @@ -<svg xmlns="http://www.w3.org/2000/svg" width="600" height="480"><path fill="#fff" d="M0 0h600v480H0z"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 444h9m451.34 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 447.9)"><tspan> 0</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 380.5h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 317h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 253.5h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 190.01h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 126.51h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 63.01h9m451.34 0h-9"/><text fill="#000" 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="#000" d="M229.57 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(229.57 465.9)"><tspan>lanczos3</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M344.65 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(344.65 465.9)"><tspan>catmull</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M459.74 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(459.74 465.9)"><tspan>nearest</tspan></text></g><path fill="none" stroke="#000" d="M114.48 63.01V444h460.34V63.01H114.48Z" 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(507.09 84.91)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M515.48 85.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M515.48 85.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M191.2 444h38.38v-53.53H191.2z" shape-rendering="crispEdges"/><path stroke="#000" d="M191.2 444v-53.52h38.37V444H191.2Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M306.29 444h38.37v-43.95h-38.37z" shape-rendering="crispEdges"/><path stroke="#000" d="M306.29 444v-43.94h38.36V444h-38.36Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M421.37 444h38.38v-7.81h-38.38z" shape-rendering="crispEdges"/><path stroke="#000" d="M421.37 444v-7.8h38.37v7.8h-38.37Z"/></g><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(507.09 102.91)"><tspan>imgproc</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M515.48 103.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M515.48 103.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M229.57 444h38.37V71.82h-38.37z" shape-rendering="crispEdges"/><path stroke="#000" d="M229.57 444V71.83h38.36V444h-38.36Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M344.65 444h38.37V166.29h-38.37z" shape-rendering="crispEdges"/><path stroke="#000" d="M344.65 444V166.3h38.36V444h-38.36Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M459.74 444h38.37V332.24h-38.37z" shape-rendering="crispEdges"/><path stroke="#000" d="M459.74 444V332.25h38.36V444h-38.36Z"/></g><path fill="none" stroke="#000" d="M114.48 63.01V444h460.34V63.01H114.48Z" color="#000"/><text color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(344.65 32.86)"><tspan>resizing</tspan></text></svg>
\ No newline at end of file +<svg xmlns="http://www.w3.org/2000/svg" width="600" height="480"><path fill="#fff" d="M0 0h600v480H0z"/><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 444h9m451.34 0h-9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="end" transform="translate(106.09 447.9)"><tspan> 0</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 380.5h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 317h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 253.5h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 190.01h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 126.51h9m451.34 0h-9"/><text fill="#000" 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><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M114.48 63.01h9m451.34 0h-9"/><text fill="#000" 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="#000" d="M229.57 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(229.57 465.9)"><tspan>lanczos3</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M344.65 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(344.65 465.9)"><tspan>catmull</tspan></text></g><g fill="none" stroke="currentColor" color="#000"><path stroke="#000" d="M459.74 444v-9m0-371.99v9"/><text fill="#000" stroke="none" font-family="Arial" font-size="12" text-anchor="middle" transform="translate(459.74 465.9)"><tspan>nearest</tspan></text></g><path fill="none" stroke="#000" d="M114.48 63.01V444h460.34V63.01H114.48Z" 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(507.09 84.91)"><tspan>fimg</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M515.48 85.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M515.48 85.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M186.41 444h28.78v-53.53h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M186.41 444v-53.52h28.77V444h-28.77Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M301.49 444h28.78v-43.95h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M301.49 444v-43.94h28.77V444h-28.77Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#9400D3" stroke="none" d="M416.58 444h28.78v-7.81h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M416.58 444v-7.8h28.77v7.8h-28.77Z"/></g><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(507.09 102.91)"><tspan>imgproc</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M515.48 103.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M515.48 103.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M215.18 444h28.78V71.82h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M215.18 444V71.83h28.77V444h-28.77Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M330.26 444h28.79V166.29h-28.79z" shape-rendering="crispEdges"/><path stroke="#000" d="M330.26 444V166.3h28.78V444h-28.78Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#009E73" stroke="none" d="M445.35 444h28.78V332.24h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M445.35 444V332.25h28.77V444h-28.77Z"/></g><text color="#000" font-family="Arial" font-size="12" text-anchor="end" transform="translate(507.09 120.91)"><tspan>resize</tspan></text><g fill="none" stroke="currentColor" color="#000"><path fill="#56B4E9" stroke="none" d="M515.48 121.51h42.56v-9h-42.56z" shape-rendering="crispEdges"/><path stroke="#000" d="M515.48 121.51h42.56v-9h-42.56v9Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#56B4E9" stroke="none" d="M243.95 444h28.78V203.79h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M243.95 444V203.8h28.77V444h-28.77Z"/></g><g fill="none" stroke="currentColor" color="#000"><path fill="#56B4E9" stroke="none" d="M359.04 444h28.78V270.9h-28.78z" shape-rendering="crispEdges"/><path stroke="#000" d="M359.04 444V270.91h28.77V444h-28.77Z"/></g><path fill="none" stroke="#000" d="M114.48 63.01V444h460.34V63.01H114.48Z" color="#000"/><text color="#000" font-family="Verdana" font-size="18" text-anchor="middle" transform="translate(344.65 32.86)"><tspan>resizing</tspan></text></svg>
\ No newline at end of file |