Skip to content

Commit

Permalink
Making insert benchmark more kickout-heavy
Browse files Browse the repository at this point in the history
By increasing expected load factor. Jointly using same load factor for
lookup benchmarks and fixing shuffling.
  • Loading branch information
panmari committed Oct 2, 2023
1 parent 5d2f798 commit d389eb2
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cuckoofilter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func benchmarkKeys(b *testing.B, size int) [][]byte {

func BenchmarkFilter_Insert(b *testing.B) {
const size = 10000
keys := benchmarkKeys(b, int(float64(size)*0.8))
keys := benchmarkKeys(b, int(float64(size)*0.9))
b.ResetTimer()

for i := 0; i < b.N; {
Expand All @@ -154,29 +154,30 @@ func BenchmarkFilter_Insert(b *testing.B) {
b.StartTimer()
for _, k := range keys {
filter.Insert(k)
i++
}
i += len(keys)
}
}

func BenchmarkFilter_Lookup(b *testing.B) {
f := NewFilter(10000)
keys := benchmarkKeys(b, 10000)
const size = 10000
f := NewFilter(size)
keys := benchmarkKeys(b, int(float64(size)*0.9))
for _, k := range keys {
f.Insert(k)
}
// One half is likely missing, other half is present.
lookupKeys := append(benchmarkKeys(b, 1000), keys[0:1000]...)
rand.New(rand.NewSource(42)).Shuffle(2000, func(i, j int) {
lookupKeys[i] = lookupKeys[j]
rand.New(rand.NewSource(42)).Shuffle(len(lookupKeys), func(i, j int) {
lookupKeys[i], lookupKeys[j] = lookupKeys[j], lookupKeys[i]
})

b.ResetTimer()
for i := 0; i < b.N; {
for _, k := range lookupKeys {
f.Lookup(k)
i++
}
i += len(lookupKeys)
}
}

Expand Down

0 comments on commit d389eb2

Please sign in to comment.