Add benchmark of HashFile

This commit is contained in:
Jakob Borg 2015-10-27 09:26:08 +01:00
parent 898fc72313
commit 1efd8d6c75
2 changed files with 40 additions and 0 deletions

1
lib/scanner/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
_random.data

View File

@ -8,13 +8,16 @@ package scanner
import (
"bytes"
"crypto/rand"
"fmt"
"io"
"os"
"path/filepath"
"reflect"
"runtime"
rdebug "runtime/debug"
"sort"
"sync"
"testing"
"github.com/syncthing/syncthing/lib/ignore"
@ -372,3 +375,39 @@ func TestSymlinkTypeEqual(t *testing.T) {
}
}
}
var initOnce sync.Once
const (
testdataSize = 17 << 20
testdataName = "_random.data"
)
func BenchmarkHashFile(b *testing.B) {
initOnce.Do(initTestFile)
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := HashFile(testdataName, protocol.BlockSize, testdataSize, nil); err != nil {
b.Fatal(err)
}
}
b.ReportAllocs()
}
func initTestFile() {
fd, err := os.Create(testdataName)
if err != nil {
panic(err)
}
lr := io.LimitReader(rand.Reader, testdataSize)
if _, err := io.Copy(fd, lr); err != nil {
panic(err)
}
if err := fd.Close(); err != nil {
panic(err)
}
}