-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaverage_test.go
35 lines (33 loc) · 994 Bytes
/
average_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
package ish
import "testing"
// BenchmarkAverageHash benchmarks the average hash algorithm against
// different image sizes and hash lengths.
func BenchmarkAverageHash(b *testing.B) {
benchmarks := []struct {
name string
filename string
width, height int
}{
{"8MP-32x32", "testdata/house-8MP-RGBA.png", 32, 32},
{"8MP-16x16", "testdata/house-8MP-RGBA.png", 16, 16},
{"8MP-8x8", "testdata/house-8MP-RGBA.png", 8, 8},
{"4MP-32x32", "testdata/house-4MP-RGBA.png", 32, 32},
{"4MP-16x16", "testdata/house-4MP-RGBA.png", 16, 16},
{"4MP-8x8", "testdata/house-4MP-RGBA.png", 8, 8},
}
for _, bm := range benchmarks {
img, _, err := LoadFile(bm.filename)
if err != nil {
b.Error("Could not load", bm.filename, ":", err)
}
b.Run(bm.name, func(b *testing.B) {
dh := NewAverageHash(bm.width, bm.height)
for i := 0; i < b.N; i++ {
_, err := dh.Hash(img)
if err != nil {
b.Error("Could not hash", bm.filename, ":", err)
}
}
})
}
}