Skip to content

Commit

Permalink
Add basic benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonynsimon committed Jul 30, 2019
1 parent c66fc7e commit 244b621
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PKG = github.com/anthonynsimon/bild
BENCHMARK = BenchmarkRAWInput
VERSION ?= dev
LDFLAGS = -ldflags "-X $(PKG)/cmd.Version=$(VERSION) -extldflags \"-static\""
MAC_LDFLAGS = -ldflags "-X $(PKG)/cmd.Version=$(VERSION)"
Expand All @@ -21,7 +20,7 @@ fmt:
go fmt ./...

bench: deps
go test ./... $(LDFLAGS) -v -run NOT_EXISTING -bench $(BENCHMARK) -benchtime 5s
go test $(LDFLAGS) -benchmem -bench=. -benchtime=5s ./...

race: deps
go test ./... -v -race -timeout 15s
Expand Down
37 changes: 37 additions & 0 deletions benchmarks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
goos: darwin
goarch: amd64

pkg: github.com/anthonynsimon/bild/convolution
BenchmarkConvolve3-8 200 43031408 ns/op 8413514 B/op 8 allocs/op
BenchmarkConvolve8-8 30 219642438 ns/op 8462644 B/op 8 allocs/op
BenchmarkConvolve32-8 2 2869904037 ns/op 8659296 B/op 8 allocs/op
BenchmarkConvolve64-8 1 15558563740 ns/op 8929584 B/op 8 allocs/op

pkg: github.com/anthonynsimon/bild/effect
BenchmarkMedian1-8 2000 6637173 ns/op 3686887 B/op 65544 allocs/op
BenchmarkMedian4-8 30 251734934 ns/op 23627210 B/op 65551 allocs/op
BenchmarkMedian8-8 2 2844636597 ns/op 84584800 B/op 65567 allocs/op

pkg: github.com/anthonynsimon/bild/noise
BenchmarkUniformMonochrome-8 200 34201494 ns/op 1048900 B/op 5 allocs/op
BenchmarkUniformColored-8 100 96952189 ns/op 1048754 B/op 4 allocs/op

pkg: github.com/anthonynsimon/bild/paint
BenchmarkFloodFill-8 100 75234019 ns/op 24616194 B/op 259073 allocs/op

pkg: github.com/anthonynsimon/bild/transform
BenchmarkResizeTenth-8 50 121855364 ns/op 74483576 B/op 13 allocs/op
BenchmarkResizeQuarter-8 50 133837811 ns/op 88081303 B/op 11 allocs/op
BenchmarkResizeHalf-8 30 192098367 ns/op 117441409 B/op 11 allocs/op
BenchmarkResize1x-8 300 26409679 ns/op 12583343 B/op 10 allocs/op
BenchmarkResize2x-8 100 72839314 ns/op 29360562 B/op 10 allocs/op
BenchmarkResize4x-8 30 235221709 ns/op 88081381 B/op 11 allocs/op
BenchmarkResize8x-8 10 852207403 ns/op 306184608 B/op 10 allocs/op
BenchmarkResize16x-8 2 3481516525 ns/op 1145045440 B/op 10 allocs/op
BenchmarkRotation256-8 5000 1232278 ns/op 524540 B/op 7 allocs/op
BenchmarkRotation512-8 2000 5393780 ns/op 2097412 B/op 7 allocs/op
BenchmarkRotation1024-8 300 24388950 ns/op 8388865 B/op 7 allocs/op
BenchmarkRotation2048-8 100 93141358 ns/op 33554704 B/op 7 allocs/op
BenchmarkRotation4096-8 20 386209001 ns/op 134217995 B/op 7 allocs/op
BenchmarkRotation8192-8 3 1751796711 ns/op 536871202 B/op 7 allocs/op
BenchmarkTranslate-8 5000 1657326 ns/op 8389660 B/op 6 allocs/op
5 changes: 4 additions & 1 deletion convolution/convolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/anthonynsimon/bild/util"
)

// benchResult is used to avoid having the compiler optimize the benchmark code calls
var benchResult interface{}

func TestConvolve(t *testing.T) {
cases := []struct {
options *Options
Expand Down Expand Up @@ -222,6 +225,6 @@ func benchConvolve(b *testing.B, w, h int, k *Kernel) {
img := image.NewRGBA(image.Rect(0, 0, w, h))
b.ResetTimer()
for n := 0; n < b.N; n++ {
Convolve(img, k, &Options{Wrap: false})
benchResult = Convolve(img, k, &Options{Wrap: false})
}
}
9 changes: 6 additions & 3 deletions effect/effect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/anthonynsimon/bild/util"
)

// benchResult is used to avoid having the compiler optimize the benchmark code calls
var benchResult interface{}

func TestSepia(t *testing.T) {
cases := []struct {
value image.Image
Expand Down Expand Up @@ -854,20 +857,20 @@ func TestUnsharpMask(t *testing.T) {
func BenchmarkMedian1(b *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, 256, 256))
for n := 0; n < b.N; n++ {
Median(img, 1)
benchResult = Median(img, 1)
}
}

func BenchmarkMedian4(b *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, 256, 256))
for n := 0; n < b.N; n++ {
Median(img, 4)
benchResult = Median(img, 4)
}
}

func BenchmarkMedian8(b *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, 256, 256))
for n := 0; n < b.N; n++ {
Median(img, 8)
benchResult = Median(img, 8)
}
}
7 changes: 5 additions & 2 deletions noise/noise_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/anthonynsimon/bild/histogram"
)

// benchResult is used to avoid having the compiler optimize the benchmark code calls
var benchResult interface{}

func TestMonochromeNoise(t *testing.T) {
cases := []struct {
w, h int
Expand Down Expand Up @@ -163,13 +166,13 @@ func TestBinaryNoise(t *testing.T) {

func BenchmarkUniformMonochrome(b *testing.B) {
for n := 0; n < b.N; n++ {
Generate(512, 512, &Options{NoiseFn: Uniform, Monochrome: true})
benchResult = Generate(512, 512, &Options{NoiseFn: Uniform, Monochrome: true})
}
}

func BenchmarkUniformColored(b *testing.B) {
for n := 0; n < b.N; n++ {
Generate(512, 512, &Options{NoiseFn: Uniform, Monochrome: false})
benchResult = Generate(512, 512, &Options{NoiseFn: Uniform, Monochrome: false})
}
}

Expand Down
2 changes: 1 addition & 1 deletion transform/resize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,6 @@ func benchResize(b *testing.B, w, h int, scale float64, f ResampleFilter) {
img := image.NewRGBA(image.Rect(0, 0, w, h))
b.ResetTimer()
for n := 0; n < b.N; n++ {
Resize(img, newW, newH, f)
benchResult = Resize(img, newW, newH, f)
}
}
2 changes: 1 addition & 1 deletion transform/rotate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,6 @@ func benchRotate(w, h int, rot float64, bench *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, w, h))
bench.ResetTimer()
for i := 0; i < bench.N; i++ {
Rotate(img, rot, nil)
benchResult = Rotate(img, rot, nil)
}
}
11 changes: 11 additions & 0 deletions transform/translate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import (
"github.com/anthonynsimon/bild/util"
)

// benchResult is used to avoid having the compiler optimize the benchmark code calls
var benchResult interface{}

func BenchmarkTranslate(b *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, 1024, 1024))
b.ResetTimer()
for n := 0; n < b.N; n++ {
benchResult = Translate(img, 512, 512)
}
}

func TestTranslate(t *testing.T) {
cases := []struct {
name string
Expand Down

0 comments on commit 244b621

Please sign in to comment.