mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-08 22:31:04 +00:00
Add benchmark of HashFile
This commit is contained in:
parent
898fc72313
commit
1efd8d6c75
1
lib/scanner/.gitignore
vendored
Normal file
1
lib/scanner/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
_random.data
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user