lib/protocol: Optimize FileKey (#7440)
This commit is contained in:
@@ -12,9 +12,11 @@ import (
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/rand"
|
||||
"github.com/syncthing/syncthing/lib/sha256"
|
||||
)
|
||||
|
||||
func TestEnDecryptName(t *testing.T) {
|
||||
@@ -180,3 +182,22 @@ func TestIsEncryptedParent(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var benchmarkFileKey struct {
|
||||
key [keySize]byte
|
||||
sync.Once
|
||||
}
|
||||
|
||||
func BenchmarkFileKey(b *testing.B) {
|
||||
benchmarkFileKey.Do(func() {
|
||||
sha256.SelectAlgo()
|
||||
rand.Read(benchmarkFileKey.key[:])
|
||||
})
|
||||
|
||||
b.ResetTimer()
|
||||
b.ReportAllocs()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
FileKey("a_kind_of_long_filename.ext", &benchmarkFileKey.key)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user