Skip to content

Commit ee6cf8e

Browse files
authored
Add imfilter benchmarks (#158)
1 parent 75f89d0 commit ee6cf8e

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

benchmark/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/Manifest.toml
2+
*.md

benchmark/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
22
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
34
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
45
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

benchmark/benchmarks.jl

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
using ImageFiltering
1+
using ImageFiltering, ImageCore
22
using PkgBenchmark
33
using BenchmarkTools
44
using Statistics: quantile, mean, median!
55

6+
function makeimages(sz)
7+
imgF32 = rand(Float32, sz)
8+
imgN0f8 = Array(rand(N0f8, sz))
9+
imggrayF32 = Array(rand(Gray{Float32}, sz))
10+
imggrayN0f8 = Array(rand(Gray{N0f8}, sz))
11+
imgrgbF32 = Array(rand(RGB{Float32}, sz))
12+
imgrgbN0f8 = Array(rand(RGB{N0f8}, sz))
13+
return ("F32"=>imgF32, "N0f8"=>imgN0f8, "GrayF32"=>imggrayF32,
14+
"GrayN0f8"=>imggrayN0f8, "RGBF32"=>imgrgbF32, "RGBN0f8"=>imgrgbN0f8)
15+
end
16+
17+
sz2str(sz) = join(map(string, sz), '×')
18+
619
SUITE = BenchmarkGroup()
720
SUITE["mapwindow"] = BenchmarkGroup()
821

@@ -12,8 +25,34 @@ let grp = SUITE["mapwindow"]
1225
img3d = randn(10,11,12)
1326
grp["cheap f, tiny window"] = @benchmarkable mapwindow(first, $img1d, (1,))
1427
grp["extrema"] = @benchmarkable mapwindow(extrema, $img2d, (5,5))
28+
grp["maximum"] = @benchmarkable mapwindow(maximum, $img2d, (5,5))
29+
grp["minimum"] = @benchmarkable mapwindow(minimum, $img2d, (5,5))
1530
grp["median!"] = @benchmarkable mapwindow(median!, $img2d, (5,5))
1631
grp["mean, small window"] = @benchmarkable mapwindow(mean, $img1d, (3,))
1732
grp["mean, large window"] = @benchmarkable mapwindow(mean, $img3d, (5,5,5))
1833
grp["expensive f"] = @benchmarkable mapwindow(x -> quantile(vec(x), 0.7), $img3d, (3,3,3))
1934
end
35+
36+
SUITE["imfilter"] = BenchmarkGroup()
37+
let grp = SUITE["imfilter"]
38+
kerninsep = (centered([-1, 0, 1]),
39+
centered([ 1/5 1/4 1/7;
40+
1/2 1/3 -1/11;
41+
-1/25 1/9 -1/7]), # has full rank so won't be factored
42+
centered(rand(3, 3, 3)))
43+
for sz in ((100, 100), (2048, 2048), (2048,), (100, 100, 100))
44+
for (aname, img) in makeimages(sz)
45+
trues = map(i->true, sz)
46+
twos = map(i->2, sz)
47+
szstr = sz2str(sz)
48+
kerniir = KernelFactors.IIRGaussian(map(i->10.0f0, sz))
49+
kerng = KernelFactors.gaussian(map(i->10.0f0, sz))
50+
for (kname, kern) in zip(("densesmall", "denselarge", "factoredsmall", "factoredlarge"),
51+
((kerninsep[length(sz)],), (Kernel.DoG(twos),), KernelFactors.sobel(trues, 1), kerng))
52+
grp[kname*"_"*aname*"_"*szstr] = @benchmarkable imfilter($img, $kern, "replicate", ImageFiltering.FIR())
53+
end
54+
grp["IIRGaussian_"*aname*"_"*szstr] = @benchmarkable imfilter($img, $kerniir, "replicate", ImageFiltering.IIR())
55+
grp["FFT_"*aname*"_"*szstr] = @benchmarkable imfilter($img, $(Kernel.DoG(twos),), "replicate", ImageFiltering.FFT())
56+
end
57+
end
58+
end

0 commit comments

Comments
 (0)