-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_test.go
61 lines (58 loc) · 1.52 KB
/
helper_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package ish
import (
"bytes"
"io/ioutil"
"testing"
)
// BenchmarkLoadFile benchmarks the load file routine against a collection
// of image sizes and file formats.
func BenchmarkLoadFile(b *testing.B) {
benchmarks := []struct {
name string
filename string
}{
{"RGBA-4MP-PNG", "testdata/house-4MP-RGBA.png"},
{"RGBA-8MP-PNG", "testdata/house-8MP-RGBA.png"},
{"RGBA-4MP-JPEG", "testdata/house-4MP-RGBA.jpeg"},
{"RGBA-8MP-JPEG", "testdata/house-8MP-RGBA.jpeg"},
}
for _, bm := range benchmarks {
b.Run(bm.name, func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _, err := LoadFile(bm.filename)
if err != nil {
b.Error("Could not load", bm.filename, ":", err)
}
}
})
}
}
// BenchmarkDecodeFile benchmarks the decoding routine against a collection
// of image sizes and file formats.
func BenchmarkDecodeFile(b *testing.B) {
benchmarks := []struct {
name string
filename string
}{
{"RGBA-4MP-PNG", "testdata/house-4MP-RGBA.png"},
{"RGBA-8MP-PNG", "testdata/house-8MP-RGBA.png"},
{"RGBA-4MP-JPEG", "testdata/house-4MP-RGBA.jpeg"},
{"RGBA-8MP-JPEG", "testdata/house-8MP-RGBA.jpeg"},
}
for _, bm := range benchmarks {
data, err := ioutil.ReadFile(bm.filename)
if err != nil {
b.Error("Could not load", bm.filename, ":", err)
}
reader := bytes.NewReader(data)
b.Run(bm.name, func(b *testing.B) {
for n := 0; n < b.N; n++ {
_, _, err := Decode(reader)
if err != nil {
b.Error("Could not decode", bm.filename, ":", err)
}
reader.Reset(data)
}
})
}
}