From df14fdedddb5a0365781630efc588c0a690d4a0e Mon Sep 17 00:00:00 2001 From: Lorenz Bauer Date: Tue, 5 Dec 2023 14:57:59 +0000 Subject: [PATCH] map: always traverse the whole map in BenchmarkIterate 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 --- map_test.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/map_test.go b/map_test.go index efe54e0ce..34b5f6501 100644 --- a/map_test.go +++ b/map_test.go @@ -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) + } } } }) @@ -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) + } } } })