Skip to content

Commit f3afdb6

Browse files
committed
cockroachkvs: add BenchmarkInitDataBlockMetadata
Add a microbenchmark measuring the cost of initializing data block metadata for a data block with the cockroachkvs key schema.
1 parent 489b133 commit f3afdb6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

cockroachkvs/cockroachkvs_bench_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,33 @@ func benchmarkCockroachDataColBlockIter(
368368
})
369369
}
370370
}
371+
372+
func BenchmarkInitDataBlockMetadata(b *testing.B) {
373+
const targetBlockSize = 32 << 10
374+
seed := uint64(20250919)
375+
rng := rand.New(rand.NewPCG(0, seed))
376+
keys, values := RandomKVs(rng, 10000, KeyGenConfig{
377+
PrefixAlphabetLen: 8,
378+
RoachKeyLen: 16,
379+
PrefixLenShared: 4,
380+
AvgKeysPerPrefix: 4,
381+
PercentLogical: 10,
382+
}, 8)
383+
384+
var w colblk.DataBlockEncoder
385+
w.Init(&KeySchema)
386+
for j := 0; w.Size() < targetBlockSize; j++ {
387+
ik := base.MakeInternalKey(keys[j], base.SeqNum(rng.Uint64N(uint64(base.SeqNumMax))), base.InternalKeyKindSet)
388+
kcmp := w.KeyWriter.ComparePrev(ik.UserKey)
389+
vp := block.InPlaceValuePrefix(kcmp.PrefixEqual())
390+
w.Add(ik, values[j], vp, kcmp, false /* isObsolete */)
391+
}
392+
finished, _ := w.Finish(w.Rows(), w.Size())
393+
394+
var md block.Metadata
395+
396+
b.ResetTimer()
397+
for range b.N {
398+
colblk.InitDataBlockMetadata(&KeySchema, &md, finished)
399+
}
400+
}

0 commit comments

Comments
 (0)