mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
bc72ac0519
commit
15c66abbe0
1 changed files with 82 additions and 0 deletions
82
lib/logstorage/bitmap_timing_test.go
Normal file
82
lib/logstorage/bitmap_timing_test.go
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package logstorage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkBitmapForEachSetBit(b *testing.B) {
|
||||||
|
const bitsLen = 64*1024
|
||||||
|
|
||||||
|
b.Run("no-zero-bits-noclear", func(b *testing.B) {
|
||||||
|
bm := getBitmap(bitsLen)
|
||||||
|
bm.setBits()
|
||||||
|
benchmarkBitmapForEachSetBit(b, bm, false)
|
||||||
|
putBitmap(bm)
|
||||||
|
})
|
||||||
|
b.Run("no-zero-bits-clear", func(b *testing.B) {
|
||||||
|
bm := getBitmap(bitsLen)
|
||||||
|
bm.setBits()
|
||||||
|
benchmarkBitmapForEachSetBit(b, bm, true)
|
||||||
|
putBitmap(bm)
|
||||||
|
})
|
||||||
|
b.Run("half-zero-bits-noclear", func(b *testing.B) {
|
||||||
|
bm := getBitmap(bitsLen)
|
||||||
|
bm.setBits()
|
||||||
|
bm.forEachSetBit(func(idx int) bool {
|
||||||
|
return idx%2 == 0
|
||||||
|
})
|
||||||
|
benchmarkBitmapForEachSetBit(b, bm, false)
|
||||||
|
putBitmap(bm)
|
||||||
|
})
|
||||||
|
b.Run("half-zero-bits-clear", func(b *testing.B) {
|
||||||
|
bm := getBitmap(bitsLen)
|
||||||
|
bm.setBits()
|
||||||
|
bm.forEachSetBit(func(idx int) bool {
|
||||||
|
return idx%2 == 0
|
||||||
|
})
|
||||||
|
benchmarkBitmapForEachSetBit(b, bm, true)
|
||||||
|
putBitmap(bm)
|
||||||
|
})
|
||||||
|
b.Run("one-set-bit-noclear", func(b *testing.B) {
|
||||||
|
bm := getBitmap(bitsLen)
|
||||||
|
bm.setBits()
|
||||||
|
bm.forEachSetBit(func(idx int) bool {
|
||||||
|
return idx == bitsLen/2
|
||||||
|
})
|
||||||
|
benchmarkBitmapForEachSetBit(b, bm, false)
|
||||||
|
putBitmap(bm)
|
||||||
|
})
|
||||||
|
b.Run("one-set-bit-clear", func(b *testing.B) {
|
||||||
|
bm := getBitmap(bitsLen)
|
||||||
|
bm.setBits()
|
||||||
|
bm.forEachSetBit(func(idx int) bool {
|
||||||
|
return idx == bitsLen/2
|
||||||
|
})
|
||||||
|
benchmarkBitmapForEachSetBit(b, bm, true)
|
||||||
|
putBitmap(bm)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkBitmapForEachSetBit(b *testing.B, bm *bitmap, isClearBits bool) {
|
||||||
|
b.SetBytes(int64(bm.bitsLen))
|
||||||
|
b.ReportAllocs()
|
||||||
|
b.RunParallel(func(pb *testing.PB) {
|
||||||
|
bmLocal := getBitmap(bm.bitsLen)
|
||||||
|
for pb.Next() {
|
||||||
|
bmLocal.copyFrom(bm)
|
||||||
|
bmLocal.forEachSetBit(func(idx int) bool {
|
||||||
|
return !isClearBits
|
||||||
|
})
|
||||||
|
if isClearBits {
|
||||||
|
if !bmLocal.isZero() {
|
||||||
|
panic("BUG: bitmap must have no set bits")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if bmLocal.isZero() {
|
||||||
|
panic("BUG: bitmap must have some set bits")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
putBitmap(bmLocal)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue