Skip to content

Commit

Permalink
Fix benchmarks and test them with PkgJogger (#107)
Browse files Browse the repository at this point in the history
* Rename benchmark file

* Use PkgJogger to test for benchmark breakage

* Fix benchmark suite

* Lighter test deps
  • Loading branch information
adrhill authored Sep 17, 2024
1 parent 332e6b6 commit 615e054
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 72 deletions.
4 changes: 2 additions & 2 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
DitherPunk = "b8f752a5-abd5-43b6-a55b-e75efda20de0"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
PkgBenchmark = "32113eaa-f34f-5b0d-bd6c-c81e245fc73d"
PkgJogger = "10150987-6cc1-4b76-abee-b1c1cbd91c01"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
52 changes: 52 additions & 0 deletions benchmark/bench_jogger.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using BenchmarkTools
using DitherPunk
using TestImages
using ColorTypes: RGB

on_CI = haskey(ENV, "GITHUB_ACTIONS")

img_gray = testimage("fabio_gray_256")
img_color = testimage("fabio_color_256")

## Define color scheme
white = RGB{Float32}(1, 1, 1)
yellow = RGB{Float32}(1, 1, 0)
green = RGB{Float32}(0, 0.5, 0)
orange = RGB{Float32}(1, 0.5, 0)
red = RGB{Float32}(1, 0, 0)
blue = RGB{Float32}(0, 0, 1)
cs = [white, yellow, green, orange, red, blue]

# Use one representative algorithm of each type
algs = Dict(
"error diffusion" => FloydSteinberg(),
"ordered dithering" => Bayer(3;),
"closest color" => ClosestColor(),
"threshold dithering" => WhiteNoiseThreshold(),
)

# Tag what is tested on each algorithm type
suite = BenchmarkGroup()
suite["error diffusion"] = BenchmarkGroup(["binary", "color"])
suite["ordered dithering"] = BenchmarkGroup(["binary", "color"])
suite["threshold dithering"] = BenchmarkGroup(["binary"])
suite["closest color"] = BenchmarkGroup(["binary", "color"])

println(suite)

for (algname, alg) in algs
suite[algname]["binary new"] = @benchmarkable dither($(img_gray), $(alg))
suite[algname]["binary inplace"] = @benchmarkable dither!($(copy(img_gray)), $(alg))

suite[algname]["per-channel new"] = @benchmarkable dither($(img_color), $(alg))
suite[algname]["per-channel inplace"] = @benchmarkable dither!(
$(copy(img_color)), $(alg)
)

if "color" in suite[algname].tags
suite[algname]["color new"] = @benchmarkable dither($(img_color), $(alg), $(cs))
suite[algname]["color inplace"] = @benchmarkable dither!(
$(copy(img_color)), $(alg), $(cs)
)
end
end
55 changes: 4 additions & 51 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,52 +1,5 @@
using BenchmarkTools
using PkgJogger
using DitherPunk
using TestImages
using ImageCore

on_CI = haskey(ENV, "GITHUB_ACTIONS")

img_gray = testimage("fabio_gray_256")
img_color = testimage("fabio_color_256")

## Define color scheme
white = RGB{Float32}(1, 1, 1)
yellow = RGB{Float32}(1, 1, 0)
green = RGB{Float32}(0, 0.5, 0)
orange = RGB{Float32}(1, 0.5, 0)
red = RGB{Float32}(1, 0, 0)
blue = RGB{Float32}(0, 0, 1)
cs = [white, yellow, green, orange, red, blue]

# Use one representative algorithm of each type
algs = Dict(
"error diffusion" => FloydSteinberg(),
"ordered dithering" => Bayer(; level=3),
"closest color" => ClosestColor(),
"threshold dithering" => WhiteNoiseThreshold(),
)

# Tag what is tested on each algorithm type
SUITE = BenchmarkGroup()
SUITE["error diffusion"] = BenchmarkGroup(["binary", "color"])
SUITE["ordered dithering"] = BenchmarkGroup(["binary", "color"])
SUITE["threshold dithering"] = BenchmarkGroup(["binary"])
SUITE["closest color"] = BenchmarkGroup(["binary", "color"])

println(SUITE)

for (algname, alg) in algs
SUITE[algname]["binary new"] = @benchmarkable dither($(img_gray), $(alg))
SUITE[algname]["binary inplace"] = @benchmarkable dither!($(copy(img_gray)), $(alg))

SUITE[algname]["per-channel new"] = @benchmarkable dither($(img_color), $(alg))
SUITE[algname]["per-channel inplace"] = @benchmarkable dither!(
$(copy(img_color)), $(alg)
)

if "color" in SUITE[algname].tags
SUITE[algname]["color new"] = @benchmarkable dither($(img_color), $(alg), $(cs))
SUITE[algname]["color inplace"] = @benchmarkable dither!(
$(copy(img_color)), $(alg), $(cs)
)
end
end
# Use PkgJogger.@jog to create the JogDitherPunk module
@jog DitherPunk
SUITE = JogDitherPunk.suite()
17 changes: 3 additions & 14 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
IndirectArrays = "9b13fd28-a010-5f03-acff-a1bbcff69959"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PkgJogger = "10150987-6cc1-4b76-abee-b1c1cbd91c01"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[compat]
Aqua = "0.8"
ColorSchemes = "3"
ImageBase = "0.1"
ImageIO = "0.6"
ImageMagick = "1"
IndirectArrays = "0.5, 1.0"
OffsetArrays = "1"
ReferenceTests = "0.10.1"
TestImages = "1"
4 changes: 4 additions & 0 deletions test/test_benchmarks.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using PkgJogger
using DitherPunk

PkgJogger.@test_benchmarks DitherPunk
2 changes: 1 addition & 1 deletion test/test_braille.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DitherPunk
using ImageBase: RGB, Gray
using ColorTypes: RGB, Gray
using Test
using ReferenceTests

Expand Down
3 changes: 2 additions & 1 deletion test/test_color.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using DitherPunk
using DitherPunk: ColorNotImplementedError
using IndirectArrays
using ImageBase
using ColorTypes: RGB, HSV
using FixedPointNumbers: N0f8
using ReferenceTests
using TestImages

Expand Down
2 changes: 1 addition & 1 deletion test/test_fixed_color.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DitherPunk
using ImageBase
using ColorTypes: RGB, HSV
using ReferenceTests
using TestImages

Expand Down
2 changes: 1 addition & 1 deletion test/test_gradient.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DitherPunk
using DitherPunk: DEFAULT_METHOD, AbstractDither
using ImageBase: Gray
using ColorTypes: Gray
using OffsetArrays

using Test
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DitherPunk
using DitherPunk: srgb2linear, clamp_limits
using ImageBase
using ColorTypes

@test srgb2linear(true) == true
@test srgb2linear(false) == false
Expand Down

0 comments on commit 615e054

Please sign in to comment.