mirror of
https://github.com/restic/restic.git
synced 2026-11-22 13:24:24 +00:00
index: make tests more representative
This commit is contained in:
1 parent
39084a912e
commit
e33ed5d0c1
1 file changed
+23
-11
@@ -463,22 +463,34 @@ func createRandomIndex(rng *rand.Rand, packfiles int) (idx *index.Index, lookupB
|
|||||||
|
|
||||||
func BenchmarkIndexHasUnknown(b *testing.B) {
|
func BenchmarkIndexHasUnknown(b *testing.B) {
|
||||||
idx, _ := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
|
idx, _ := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
|
||||||
lookupBh := restic.NewRandomBlobHandle()
|
handles := make([]restic.BlobHandle, 0, 100000)
|
||||||
|
for i := 0; i < cap(handles); i++ {
|
||||||
|
handles = append(handles, restic.NewRandomBlobHandle())
|
||||||
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
|
// use multiple handles to reduce cache effects
|
||||||
for i := 0; i < b.N; i++ {
|
for _, handle := range handles {
|
||||||
idx.Has(lookupBh)
|
idx.Has(handle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkIndexHasKnown(b *testing.B) {
|
func BenchmarkIndexHasKnown(b *testing.B) {
|
||||||
idx, lookupBh := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
|
idx, _ := createRandomIndex(rand.New(rand.NewSource(0)), 200000)
|
||||||
|
handles := make([]restic.BlobHandle, 0, 100000)
|
||||||
|
for handle := range idx.Values() {
|
||||||
|
handles = append(handles, handle.BlobHandle)
|
||||||
|
if len(handles) == cap(handles) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
b.ResetTimer()
|
for b.Loop() {
|
||||||
|
// use multiple handles to reduce cache effects
|
||||||
for i := 0; i < b.N; i++ {
|
for _, handle := range handles {
|
||||||
idx.Has(lookupBh)
|
idx.Has(handle)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +498,7 @@ func BenchmarkIndexAlloc(b *testing.B) {
|
|||||||
rng := rand.New(rand.NewSource(0))
|
rng := rand.New(rand.NewSource(0))
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
createRandomIndex(rng, 200000)
|
createRandomIndex(rng, 200000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user