lib/mergeset: fix data race in BenchmarkInmemoryBlockMarshal

This commit is contained in:
Aliaksandr Valialkin 2023-01-23 19:43:18 -08:00
parent 30e968df6d
commit 7030429958
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -50,19 +50,20 @@ func BenchmarkInmemoryBlockMarshal(b *testing.B) {
func benchmarkInmemoryBlockMarshal(b *testing.B, prefix string) { func benchmarkInmemoryBlockMarshal(b *testing.B, prefix string) {
const itemsCount = 500 const itemsCount = 500
var ibSrc inmemoryBlock
for i := 0; i < itemsCount; i++ {
item := []byte(fmt.Sprintf("%s%d", prefix, i))
if !ibSrc.Add(item) {
b.Fatalf("cannot add more than %d items", i)
}
}
sort.Sort(&ibSrc)
b.ResetTimer() b.ResetTimer()
b.SetBytes(int64(itemsCount * len(prefix))) b.SetBytes(int64(itemsCount * len(prefix)))
b.ReportAllocs() b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
var ibSrc inmemoryBlock
for i := 0; i < itemsCount; i++ {
item := []byte(fmt.Sprintf("%s%d", prefix, i))
if !ibSrc.Add(item) {
b.Fatalf("cannot add more than %d items", i)
}
}
sort.Sort(&ibSrc)
var sb storageBlock var sb storageBlock
var firstItem, commonPrefix []byte var firstItem, commonPrefix []byte
var n uint32 var n uint32