Skip to content

Commit 7bf6000

Browse files
committed
arenaskl: add BenchmarkCockroachKeysSeekPrefixGE
Add a new microbenchmark that benchmarks SeekPrefixGE but with Cockroach keys and the Cockroach comparator.
1 parent fdb9ac7 commit 7bf6000

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2025 The LevelDB-Go and Pebble Authors. All rights reserved. Use
2+
// of this source code is governed by a BSD-style license that can be found in
3+
// the LICENSE file.
4+
5+
package arenaskl_test
6+
7+
import (
8+
"fmt"
9+
"math/rand/v2"
10+
"testing"
11+
"time"
12+
13+
"github.com/cockroachdb/pebble/cockroachkvs"
14+
"github.com/cockroachdb/pebble/internal/arenaskl"
15+
"github.com/cockroachdb/pebble/internal/base"
16+
)
17+
18+
// BenchmarkCockroachKeysSeekPrefixGE looks at the performance of repeated calls
19+
// to SeekPrefixGE, with different skip distances and different settings of
20+
// trySeekUsingNext.
21+
func BenchmarkCockroachKeysSeekPrefixGE(b *testing.B) {
22+
l := arenaskl.NewSkiplist(arenaskl.NewArena(make([]byte, 64<<20)), cockroachkvs.Compare)
23+
rng := rand.New(rand.NewPCG(0, uint64(10000)))
24+
keys, vals := cockroachkvs.RandomKVs(rng, 1000000, cockroachkvs.KeyGenConfig{
25+
PrefixAlphabetLen: 26,
26+
PrefixLenShared: 4,
27+
RoachKeyLen: 16,
28+
AvgKeysPerPrefix: 2,
29+
BaseWallTime: uint64(time.Now().UnixNano()),
30+
}, 8 /* value len */)
31+
prefixes := make([][]byte, len(keys))
32+
for i := range prefixes {
33+
prefixes[i] = keys[i][:cockroachkvs.Split(keys[i])]
34+
}
35+
36+
var count int
37+
for count = 0; ; count++ {
38+
if err := l.Add(base.InternalKey{UserKey: keys[count]}, vals[count]); err == arenaskl.ErrArenaFull {
39+
break
40+
}
41+
}
42+
43+
for _, skip := range []int{1, 2, 4, 8, 16} {
44+
for _, useNext := range []bool{false, true} {
45+
b.Run(fmt.Sprintf("skip=%d/use-next=%t", skip, useNext), func(b *testing.B) {
46+
it := l.NewIter(nil, nil)
47+
j := 0
48+
b.ResetTimer()
49+
it.SeekPrefixGE(prefixes[j], keys[j], base.SeekGEFlagsNone)
50+
for i := 1; i < b.N; i++ {
51+
j += skip
52+
var flags base.SeekGEFlags
53+
if useNext {
54+
flags = flags.EnableTrySeekUsingNext()
55+
}
56+
if j >= count {
57+
j = 0
58+
flags = flags.DisableTrySeekUsingNext()
59+
}
60+
it.SeekPrefixGE(prefixes[j], keys[j], flags)
61+
}
62+
})
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)