diff --git a/README.md b/README.md index 60a6ffe..394bc00 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ func main() { ## Release Note +### v1.0.1 +- Perception/ExtPerception hash creation times are reduced + ### v1.0.0 **IMPORTANT** goimagehash v1.0.0 does not have compatible with the before version for future features diff --git a/hashcompute_test.go b/hashcompute_test.go index 575d84d..83711a9 100644 --- a/hashcompute_test.go +++ b/hashcompute_test.go @@ -98,7 +98,7 @@ func TestHashCompute(t *testing.T) { } } -func NilHashComputeTest(t *testing.T) { +func TestNilHashCompute(t *testing.T) { hash, err := AverageHash(nil) if err == nil { t.Errorf("Error should be got.") @@ -124,6 +124,40 @@ func NilHashComputeTest(t *testing.T) { } } +func TestNilExtendHashCompute(t *testing.T) { + hash, err := ExtAverageHash(nil, 8, 8) + if err == nil { + t.Errorf("Error should be got.") + } + if hash != nil { + t.Errorf("Nil hash should be got. but got %v", hash) + } + + hash, err = ExtDifferenceHash(nil, 8, 8) + if err == nil { + t.Errorf("Error should be got.") + } + if hash != nil { + t.Errorf("Nil hash should be got. but got %v", hash) + } + + hash, err = ExtPerceptionHash(nil, 8, 8) + if err == nil { + t.Errorf("Error should be got.") + } + if hash != nil { + t.Errorf("Nil hash should be got. but got %v", hash) + } + + hash, err = ExtPerceptionHash(nil, 8, 9) + if err == nil { + t.Errorf("Error should be got.") + } + if hash != nil { + t.Errorf("Nil hash should be got. but got %v", hash) + } +} + func BenchmarkDistanceIdentical(b *testing.B) { h1 := &ImageHash{hash: 0xe48ae53c05e502f7} h2 := &ImageHash{hash: 0xe48ae53c05e502f7} @@ -295,3 +329,39 @@ func BenchmarkPerceptionHash(b *testing.B) { } } } + +func BenchmarkAverageHash(b *testing.B) { + file1, err := os.Open("_examples/sample3.jpg") + if err != nil { + b.Errorf("%s", err) + } + defer file1.Close() + img1, err := jpeg.Decode(file1) + if err != nil { + b.Errorf("%s", err) + } + for i := 0; i < b.N; i++ { + _, err := ExtAverageHash(img1, 8, 8) + if err != nil { + b.Errorf("%s", err) + } + } +} + +func BenchmarkDiffrenceHash(b *testing.B) { + file1, err := os.Open("_examples/sample3.jpg") + if err != nil { + b.Errorf("%s", err) + } + defer file1.Close() + img1, err := jpeg.Decode(file1) + if err != nil { + b.Errorf("%s", err) + } + for i := 0; i < b.N; i++ { + _, err := ExtDifferenceHash(img1, 8, 8) + if err != nil { + b.Errorf("%s", err) + } + } +}