github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/pkg/images/bench_test.go (about) 1 /* 2 Copyright 2013 The Camlistore AUTHORS 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package images 18 19 import ( 20 "image" 21 "testing" 22 ) 23 24 func benchRescale(b *testing.B, w, h, thumbW, thumbH int) { 25 // Most JPEGs are YCbCr, so bench with that. 26 im := image.NewYCbCr(image.Rect(0, 0, w, h), image.YCbCrSubsampleRatio422) 27 o := &DecodeOpts{MaxWidth: thumbW, MaxHeight: thumbH} 28 b.ResetTimer() 29 for i := 0; i < b.N; i++ { 30 _ = rescale(im, o, false) 31 } 32 } 33 34 func BenchmarkRescale1000To50(b *testing.B) { 35 orig, thumb := 1000, 50 36 benchRescale(b, orig, orig, thumb, thumb) 37 } 38 39 func BenchmarkRescale1000To100(b *testing.B) { 40 orig, thumb := 1000, 100 41 benchRescale(b, orig, orig, thumb, thumb) 42 } 43 44 func BenchmarkRescale1000To200(b *testing.B) { 45 orig, thumb := 1000, 200 46 benchRescale(b, orig, orig, thumb, thumb) 47 } 48 49 func BenchmarkRescale1000To400(b *testing.B) { 50 orig, thumb := 1000, 400 51 benchRescale(b, orig, orig, thumb, thumb) 52 } 53 54 func BenchmarkRescale1000To800(b *testing.B) { 55 orig, thumb := 1000, 800 56 benchRescale(b, orig, orig, thumb, thumb) 57 } 58 59 func BenchmarkRescale2000To50(b *testing.B) { 60 orig, thumb := 2000, 50 61 benchRescale(b, orig, orig, thumb, thumb) 62 } 63 64 func BenchmarkRescale2000To100(b *testing.B) { 65 orig, thumb := 2000, 100 66 benchRescale(b, orig, orig, thumb, thumb) 67 } 68 69 func BenchmarkRescale2000To200(b *testing.B) { 70 orig, thumb := 2000, 200 71 benchRescale(b, orig, orig, thumb, thumb) 72 } 73 74 func BenchmarkRescale2000To400(b *testing.B) { 75 orig, thumb := 2000, 400 76 benchRescale(b, orig, orig, thumb, thumb) 77 } 78 79 func BenchmarkRescale2000To800(b *testing.B) { 80 orig, thumb := 2000, 800 81 benchRescale(b, orig, orig, thumb, thumb) 82 } 83 84 func BenchmarkRescale4000To50(b *testing.B) { 85 orig, thumb := 4000, 50 86 benchRescale(b, orig, orig, thumb, thumb) 87 } 88 89 func BenchmarkRescale4000To100(b *testing.B) { 90 orig, thumb := 4000, 100 91 benchRescale(b, orig, orig, thumb, thumb) 92 } 93 94 func BenchmarkRescale4000To200(b *testing.B) { 95 orig, thumb := 4000, 200 96 benchRescale(b, orig, orig, thumb, thumb) 97 } 98 99 func BenchmarkRescale4000To400(b *testing.B) { 100 orig, thumb := 4000, 400 101 benchRescale(b, orig, orig, thumb, thumb) 102 } 103 104 func BenchmarkRescale4000To800(b *testing.B) { 105 orig, thumb := 4000, 800 106 benchRescale(b, orig, orig, thumb, thumb) 107 } 108 109 func BenchmarkRescale8000To50(b *testing.B) { 110 orig, thumb := 8000, 50 111 benchRescale(b, orig, orig, thumb, thumb) 112 } 113 114 func BenchmarkRescale8000To100(b *testing.B) { 115 orig, thumb := 8000, 100 116 benchRescale(b, orig, orig, thumb, thumb) 117 } 118 119 func BenchmarkRescale8000To200(b *testing.B) { 120 orig, thumb := 8000, 200 121 benchRescale(b, orig, orig, thumb, thumb) 122 } 123 124 func BenchmarkRescale8000To400(b *testing.B) { 125 orig, thumb := 8000, 400 126 benchRescale(b, orig, orig, thumb, thumb) 127 } 128 129 func BenchmarkRescale8000To800(b *testing.B) { 130 orig, thumb := 8000, 800 131 benchRescale(b, orig, orig, thumb, thumb) 132 }