2016-12-14 23:30:29 +00:00
|
|
|
// Copyright (C) 2016 The Syncthing Authors.
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
2017-02-09 06:52:18 +00:00
|
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-12-14 23:30:29 +00:00
|
|
|
|
|
|
|
package weakhash
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
2017-01-04 21:04:13 +00:00
|
|
|
|
|
|
|
"github.com/chmduquesne/rollinghash/adler32"
|
2016-12-14 23:30:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const testFile = "../model/testdata/~syncthing~file.tmp"
|
2017-01-04 21:04:13 +00:00
|
|
|
const size = 128 << 10
|
2016-12-14 23:30:29 +00:00
|
|
|
|
|
|
|
func BenchmarkFind1MFile(b *testing.B) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(1 << 20)
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
fd, err := os.Open(testFile)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
2017-01-04 21:04:13 +00:00
|
|
|
_, err = Find(fd, []uint32{0, 1, 2}, size)
|
2016-12-14 23:30:29 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
fd.Close()
|
|
|
|
}
|
|
|
|
}
|
2017-01-04 21:04:13 +00:00
|
|
|
|
|
|
|
func BenchmarkWeakHashAdler32(b *testing.B) {
|
|
|
|
data := make([]byte, size)
|
|
|
|
hf := adler32.New()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
hf.Write(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
_ = hf.Sum32()
|
|
|
|
b.SetBytes(size)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkWeakHashAdler32Roll(b *testing.B) {
|
|
|
|
data := make([]byte, size)
|
|
|
|
hf := adler32.New()
|
|
|
|
hf.Write(data)
|
|
|
|
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
for i := 0; i <= size; i++ {
|
|
|
|
hf.Roll('a')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
b.SetBytes(size)
|
|
|
|
}
|