2019-05-22 23:16:55 +02:00
|
|
|
package storage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkBlockStreamReaderBlocksWorstCase(b *testing.B) {
|
|
|
|
benchmarkBlockStreamReader(b, benchInmemoryPartWorstCase, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBlockStreamReaderBlocksBestCase(b *testing.B) {
|
|
|
|
benchmarkBlockStreamReader(b, benchInmemoryPartBestCase, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBlockStreamReaderRowsWorstCase(b *testing.B) {
|
|
|
|
benchmarkBlockStreamReader(b, benchInmemoryPartWorstCase, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkBlockStreamReaderRowsBestCase(b *testing.B) {
|
|
|
|
benchmarkBlockStreamReader(b, benchInmemoryPartBestCase, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkBlockStreamReader(b *testing.B, mp *inmemoryPart, readRows bool) {
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.SetBytes(int64(mp.ph.RowsCount))
|
|
|
|
b.RunParallel(func(pb *testing.PB) {
|
|
|
|
var bsr blockStreamReader
|
|
|
|
blockNum := 0
|
|
|
|
for pb.Next() {
|
2023-04-15 00:46:09 +02:00
|
|
|
bsr.MustInitFromInmemoryPart(mp)
|
2019-05-22 23:16:55 +02:00
|
|
|
for bsr.NextBlock() {
|
|
|
|
if !readRows {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if err := bsr.Block.UnmarshalData(); err != nil {
|
2020-06-30 21:58:18 +02:00
|
|
|
panic(fmt.Errorf("unexpected error when unmarshaling rows on block %d: %w", blockNum, err))
|
2019-05-22 23:16:55 +02:00
|
|
|
}
|
|
|
|
for bsr.Block.nextRow() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := bsr.Error(); err != nil {
|
2020-06-30 21:58:18 +02:00
|
|
|
panic(fmt.Errorf("unexpected error when reading block %d: %w", blockNum, err))
|
2019-05-22 23:16:55 +02:00
|
|
|
}
|
|
|
|
blockNum++
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var benchInmemoryPartWorstCase = newTestInmemoryPart(benchRawRowsWorstCase)
|
|
|
|
var benchInmemoryPartBestCase = newTestInmemoryPart(benchRawRowsBestCase)
|
|
|
|
|
|
|
|
func newTestInmemoryPart(rows []rawRow) *inmemoryPart {
|
|
|
|
var mp inmemoryPart
|
|
|
|
mp.InitFromRows(rows)
|
|
|
|
return &mp
|
|
|
|
}
|