Skip to content

Commit

Permalink
map: always traverse the whole map in BenchmarkIterate
Browse files Browse the repository at this point in the history
The batch benchmarks currently rely on allocating output buffers
equal to the size of the map to do a full iteration in a single
syscall. This is not a very realistic scenario because users will
most likely allocate fixed batch sizes instad. Nevertheless this
gives a useful "fastest possible dump".

Adjust the batch benchmarks to include cursor allocation and
checking for ErrKeyNotFound to make them a bit more realistic.

Signed-off-by: Lorenz Bauer <lmb@isovalent.com>
  • Loading branch information
lmb committed Dec 5, 2023
1 parent 5b9d6c7 commit df14fde
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2093,11 +2093,16 @@ func BenchmarkIterate(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

var cursor BatchCursor
for i := 0; i < b.N; i++ {
_, err := m.BatchLookup(&cursor, k, v, nil)
if err != nil && !errors.Is(err, ErrKeyNotExist) {
b.Fatal(err)
var cursor BatchCursor
for {
_, err := m.BatchLookup(&cursor, k, v, nil)
if errors.Is(err, ErrKeyNotExist) {
break
}
if err != nil {
b.Fatal(err)
}
}
}
})
Expand All @@ -2117,9 +2122,14 @@ func BenchmarkIterate(b *testing.B) {
b.StartTimer()

var cursor BatchCursor
_, err := m.BatchLookupAndDelete(&cursor, k, v, nil)
if err != nil && !errors.Is(err, ErrKeyNotExist) {
b.Fatal(err)
for {
_, err := m.BatchLookupAndDelete(&cursor, k, v, nil)
if errors.Is(err, ErrKeyNotExist) {
break
}
if err != nil {
b.Fatal(err)
}
}
}
})
Expand Down

0 comments on commit df14fde

Please sign in to comment.