perkeep/pkg/images/bench_test.go

133 lines
3.2 KiB
Go
Raw Normal View History

pkg/images: add benchmark for resizing images. Sample run on my computer: $ go test -bench . -benchmem PASS BenchmarkRescale1000To50 50 45211076 ns/op 92224 B/op 3 allocs/op BenchmarkRescale1000To100 50 45182185 ns/op 364608 B/op 3 allocs/op BenchmarkRescale1000To200 50 46602272 ns/op 1445952 B/op 3 allocs/op BenchmarkRescale1000To400 50 61513579 ns/op 5763136 B/op 3 allocs/op BenchmarkRescale1000To800 20 104372086 ns/op 23040064 B/op 3 allocs/op BenchmarkRescale2000To50 10 179838094 ns/op 92224 B/op 3 allocs/op BenchmarkRescale2000To100 10 180684898 ns/op 364608 B/op 3 allocs/op BenchmarkRescale2000To200 10 181488279 ns/op 1445952 B/op 3 allocs/op BenchmarkRescale2000To400 10 186902466 ns/op 5763136 B/op 3 allocs/op BenchmarkRescale2000To800 10 246418484 ns/op 23040064 B/op 3 allocs/op BenchmarkRescale4000To50 2000 1305587 ns/op 133251 B/op 5 allocs/op BenchmarkRescale4000To100 500 5179999 ns/op 528512 B/op 5 allocs/op BenchmarkRescale4000To200 100 20733512 ns/op 2089088 B/op 5 allocs/op BenchmarkRescale4000To400 20 82820323 ns/op 8323200 B/op 5 allocs/op BenchmarkRescale4000To800 5 333289471 ns/op 33280128 B/op 5 allocs/op BenchmarkRescale8000To50 2000 1397384 ns/op 133251 B/op 5 allocs/op BenchmarkRescale8000To100 500 5219709 ns/op 528515 B/op 5 allocs/op BenchmarkRescale8000To200 100 20863617 ns/op 2089089 B/op 5 allocs/op BenchmarkRescale8000To400 20 83260367 ns/op 8323200 B/op 5 allocs/op BenchmarkRescale8000To800 5 331035176 ns/op 33280128 B/op 5 allocs/op ok camlistore.org/pkg/images 46.780s Change-Id: Iab21f28f06681faf44b01a75c3bb8b23fb508a81
2013-12-09 06:36:09 +00:00
/*
Copyright 2013 The Camlistore AUTHORS
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package images
import (
"image"
"testing"
)
func benchRescale(b *testing.B, w, h, thumbW, thumbH int) {
// Most JPEGs are YCbCr, so bench with that.
im := image.NewYCbCr(image.Rect(0, 0, w, h), image.YCbCrSubsampleRatio422)
o := &DecodeOpts{MaxWidth: thumbW, MaxHeight: thumbH}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = rescale(im, o, false)
pkg/images: add benchmark for resizing images. Sample run on my computer: $ go test -bench . -benchmem PASS BenchmarkRescale1000To50 50 45211076 ns/op 92224 B/op 3 allocs/op BenchmarkRescale1000To100 50 45182185 ns/op 364608 B/op 3 allocs/op BenchmarkRescale1000To200 50 46602272 ns/op 1445952 B/op 3 allocs/op BenchmarkRescale1000To400 50 61513579 ns/op 5763136 B/op 3 allocs/op BenchmarkRescale1000To800 20 104372086 ns/op 23040064 B/op 3 allocs/op BenchmarkRescale2000To50 10 179838094 ns/op 92224 B/op 3 allocs/op BenchmarkRescale2000To100 10 180684898 ns/op 364608 B/op 3 allocs/op BenchmarkRescale2000To200 10 181488279 ns/op 1445952 B/op 3 allocs/op BenchmarkRescale2000To400 10 186902466 ns/op 5763136 B/op 3 allocs/op BenchmarkRescale2000To800 10 246418484 ns/op 23040064 B/op 3 allocs/op BenchmarkRescale4000To50 2000 1305587 ns/op 133251 B/op 5 allocs/op BenchmarkRescale4000To100 500 5179999 ns/op 528512 B/op 5 allocs/op BenchmarkRescale4000To200 100 20733512 ns/op 2089088 B/op 5 allocs/op BenchmarkRescale4000To400 20 82820323 ns/op 8323200 B/op 5 allocs/op BenchmarkRescale4000To800 5 333289471 ns/op 33280128 B/op 5 allocs/op BenchmarkRescale8000To50 2000 1397384 ns/op 133251 B/op 5 allocs/op BenchmarkRescale8000To100 500 5219709 ns/op 528515 B/op 5 allocs/op BenchmarkRescale8000To200 100 20863617 ns/op 2089089 B/op 5 allocs/op BenchmarkRescale8000To400 20 83260367 ns/op 8323200 B/op 5 allocs/op BenchmarkRescale8000To800 5 331035176 ns/op 33280128 B/op 5 allocs/op ok camlistore.org/pkg/images 46.780s Change-Id: Iab21f28f06681faf44b01a75c3bb8b23fb508a81
2013-12-09 06:36:09 +00:00
}
}
func BenchmarkRescale1000To50(b *testing.B) {
orig, thumb := 1000, 50
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale1000To100(b *testing.B) {
orig, thumb := 1000, 100
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale1000To200(b *testing.B) {
orig, thumb := 1000, 200
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale1000To400(b *testing.B) {
orig, thumb := 1000, 400
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale1000To800(b *testing.B) {
orig, thumb := 1000, 800
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale2000To50(b *testing.B) {
orig, thumb := 2000, 50
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale2000To100(b *testing.B) {
orig, thumb := 2000, 100
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale2000To200(b *testing.B) {
orig, thumb := 2000, 200
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale2000To400(b *testing.B) {
orig, thumb := 2000, 400
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale2000To800(b *testing.B) {
orig, thumb := 2000, 800
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale4000To50(b *testing.B) {
orig, thumb := 4000, 50
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale4000To100(b *testing.B) {
orig, thumb := 4000, 100
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale4000To200(b *testing.B) {
orig, thumb := 4000, 200
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale4000To400(b *testing.B) {
orig, thumb := 4000, 400
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale4000To800(b *testing.B) {
orig, thumb := 4000, 800
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale8000To50(b *testing.B) {
orig, thumb := 8000, 50
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale8000To100(b *testing.B) {
orig, thumb := 8000, 100
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale8000To200(b *testing.B) {
orig, thumb := 8000, 200
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale8000To400(b *testing.B) {
orig, thumb := 8000, 400
benchRescale(b, orig, orig, thumb, thumb)
}
func BenchmarkRescale8000To800(b *testing.B) {
orig, thumb := 8000, 800
benchRescale(b, orig, orig, thumb, thumb)
}