Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions frac/processor/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ func TestSingleSourceCountAggregatorWithInterval(t *testing.T) {
assert.Equal(t, int64(1), agg.notExists)
}

func Generate(n int) ([]uint32, uint32) {
const benchRandSeed int64 = 1

func Generate(r *rand.Rand, n int) ([]uint32, uint32) {
v := make([]uint32, n)
last := uint32(1)
for i := range v {
v[i] = last
last += uint32(1 + rand.Intn(5))
last += uint32(1 + r.Intn(5))
}
return v, last
}
Expand All @@ -94,11 +96,12 @@ func BenchmarkAggDeep(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
v, _ := Generate(s)
r := rand.New(rand.NewSource(benchRandSeed))
v, _ := Generate(r, s)
src := node.NewSourcedNodeWrapper(node.NewStatic(v, false), 0)
iter := NewSourcedNodeIterator(src, nil, make([]uint32, 1), iteratorLimit{limit: 0, err: consts.ErrTooManyGroupTokens}, false)
n := NewSingleSourceCountAggregator(iter, provideExtractTimeFunc(nil, nil, 0))
vals, _ := Generate(s)
vals, _ := Generate(r, s)

for b.Loop() {
for _, v := range vals {
Expand All @@ -116,13 +119,14 @@ func BenchmarkAggWide(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
v, _ := Generate(s)
r := rand.New(rand.NewSource(benchRandSeed))
v, _ := Generate(r, s)

factor := int(math.Sqrt(float64(s)))
wide := make([][]uint32, s/factor)
for i := range wide {
for range factor {
wide[i] = append(wide[i], v[rand.Intn(s)])
wide[i] = append(wide[i], v[r.Intn(s)])
}
slices.Sort(wide[i])
}
Expand All @@ -131,7 +135,7 @@ func BenchmarkAggWide(b *testing.B) {

iter := NewSourcedNodeIterator(source, nil, make([]uint32, len(wide)), iteratorLimit{limit: 0, err: consts.ErrTooManyGroupTokens}, false)
n := NewSingleSourceCountAggregator(iter, provideExtractTimeFunc(nil, nil, 0))
vals, _ := Generate(s)
vals, _ := Generate(r, s)

for b.Loop() {
for _, v := range vals {
Expand Down
47 changes: 28 additions & 19 deletions node/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ import (
"github.com/stretchr/testify/assert"
)

func newNodeStaticSize(size int) *staticAsc {
data, _ := Generate(size)
const benchRandSeed int64 = 1

func newNodeStaticSize(r *rand.Rand, size int) *staticAsc {
data, _ := Generate(r, size)
return &staticAsc{staticCursor: staticCursor{data: data}}
}

func Generate(n int) ([]uint32, uint32) {
func Generate(r *rand.Rand, n int) ([]uint32, uint32) {
v := make([]uint32, n)
last := uint32(1)
for i := 0; i < len(v); i++ {
v[i] = last
last += uint32(1 + rand.Intn(5))
last += uint32(1 + r.Intn(5))
}
return v, last
}
Expand All @@ -28,7 +30,8 @@ func BenchmarkNot(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
v, last := Generate(s)
r := rand.New(rand.NewSource(benchRandSeed))
v, last := Generate(r, s)
res := make([]uint32, 0, last+1)
n := NewNot(NewStatic(v, false), 1, last, false)

Expand Down Expand Up @@ -64,8 +67,9 @@ func BenchmarkOr(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
r := rand.New(rand.NewSource(benchRandSeed))
res := make([]uint32, 0, s*2)
n := NewOr(newNodeStaticSize(s), newNodeStaticSize(s), false)
n := NewOr(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)

for b.Loop() {
res = readAllInto(n, res)
Expand All @@ -81,8 +85,9 @@ func BenchmarkAnd(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
r := rand.New(rand.NewSource(benchRandSeed))
res := make([]uint32, 0, s)
n := NewAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n := NewAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)

for b.Loop() {
res = readAllInto(n, res)
Expand All @@ -98,8 +103,9 @@ func BenchmarkNAnd(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
r := rand.New(rand.NewSource(benchRandSeed))
res := make([]uint32, 0, s)
n := NewNAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n := NewNAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)

for b.Loop() {
res = readAllInto(n, res)
Expand All @@ -115,10 +121,11 @@ func BenchmarkAndTree(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
n1 := NewAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n2 := NewAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n3 := NewAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n4 := NewAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
r := rand.New(rand.NewSource(benchRandSeed))
n1 := NewAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n2 := NewAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n3 := NewAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n4 := NewAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n12 := NewAnd(n1, n2, false)
n34 := NewAnd(n3, n4, false)
n := NewAnd(n12, n34, false)
Expand All @@ -138,10 +145,11 @@ func BenchmarkOrTree(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
n1 := NewOr(newNodeStaticSize(s), newNodeStaticSize(s), false)
n2 := NewOr(newNodeStaticSize(s), newNodeStaticSize(s), false)
n3 := NewOr(newNodeStaticSize(s), newNodeStaticSize(s), false)
n4 := NewOr(newNodeStaticSize(s), newNodeStaticSize(s), false)
r := rand.New(rand.NewSource(benchRandSeed))
n1 := NewOr(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n2 := NewOr(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n3 := NewOr(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n4 := NewOr(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n12 := NewOr(n1, n2, false)
n34 := NewOr(n3, n4, false)
n := NewOr(n12, n34, false)
Expand All @@ -162,10 +170,11 @@ func BenchmarkComplex(b *testing.B) {

for _, s := range sizes {
b.Run(fmt.Sprintf("size=%d", s), func(b *testing.B) {
r := rand.New(rand.NewSource(benchRandSeed))
res := make([]uint32, 0, s*2)
n1 := NewAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n2 := NewOr(newNodeStaticSize(s), newNodeStaticSize(s), false)
n3 := NewNAnd(newNodeStaticSize(s), newNodeStaticSize(s), false)
n1 := NewAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n2 := NewOr(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n3 := NewNAnd(newNodeStaticSize(r, s), newNodeStaticSize(r, s), false)
n12 := NewOr(n1, n2, false)
n := NewAnd(n12, n3, false)

Expand Down
Loading