mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/uint64set: add benchmarks for Set.Union
This commit is contained in:
parent
3748fb24b6
commit
1b5f02e293
1 changed files with 46 additions and 0 deletions
|
@ -8,6 +8,52 @@ import (
|
|||
"github.com/valyala/fastrand"
|
||||
)
|
||||
|
||||
func BenchmarkUnionNoOverlap(b *testing.B) {
|
||||
for _, itemsCount := range []int{1e3, 1e4, 1e5, 1e6, 1e7} {
|
||||
start := uint64(time.Now().UnixNano())
|
||||
sa := createRangeSet(start, itemsCount)
|
||||
sb := createRangeSet(start+uint64(itemsCount), itemsCount)
|
||||
b.Run(fmt.Sprintf("items_%d", itemsCount), func(b *testing.B) {
|
||||
benchmarkUnion(b, sa, sb)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUnionPartialOverlap(b *testing.B) {
|
||||
for _, itemsCount := range []int{1e3, 1e4, 1e5, 1e6, 1e7} {
|
||||
start := uint64(time.Now().UnixNano())
|
||||
sa := createRangeSet(start, itemsCount)
|
||||
sb := createRangeSet(start+uint64(itemsCount/2), itemsCount)
|
||||
b.Run(fmt.Sprintf("items_%d", itemsCount), func(b *testing.B) {
|
||||
benchmarkUnion(b, sa, sb)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkUnionFullOverlap(b *testing.B) {
|
||||
for _, itemsCount := range []int{1e3, 1e4, 1e5, 1e6, 1e7} {
|
||||
start := uint64(time.Now().UnixNano())
|
||||
sa := createRangeSet(start, itemsCount)
|
||||
sb := createRangeSet(start, itemsCount)
|
||||
b.Run(fmt.Sprintf("items_%d", itemsCount), func(b *testing.B) {
|
||||
benchmarkUnion(b, sa, sb)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkUnion(b *testing.B, sa, sb *Set) {
|
||||
b.ReportAllocs()
|
||||
b.SetBytes(int64(sa.Len() + sb.Len()))
|
||||
b.RunParallel(func(pb *testing.PB) {
|
||||
for pb.Next() {
|
||||
saCopy := sa.Clone()
|
||||
sbCopy := sb.Clone()
|
||||
saCopy.Union(sb)
|
||||
sbCopy.Union(sa)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkIntersectNoOverlap(b *testing.B) {
|
||||
for _, itemsCount := range []int{1e3, 1e4, 1e5, 1e6, 1e7} {
|
||||
start := uint64(time.Now().UnixNano())
|
||||
|
|
Loading…
Reference in a new issue