lib/protocol: Optimize FileKey (#7440)

This commit is contained in:
greatroar
2021-03-07 18:44:21 +01:00
committed by GitHub
parent 587c89d979
commit c00520281b
2 changed files with 25 additions and 2 deletions
+21
View File
@@ -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)
}
}