bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/bosun/expr/perf_test.go (about)

     1  package expr
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"bosun.org/opentsdb"
     8  )
     9  
    10  func TestSlowUnion(t *testing.T) {
    11  	ra, rb := buildFakeResults()
    12  	e := State{}
    13  	e.unjoinedOk = true
    14  	x := e.union(ra, rb, "")
    15  	if len(x) != 1000 {
    16  		t.Errorf("Bad length %d != 1000", len(x))
    17  	}
    18  }
    19  
    20  func buildFakeResults() (ra, rb *Results) {
    21  	ra = &Results{}
    22  	rb = &Results{}
    23  	for i := 0; i < 50000; i++ {
    24  		tags := opentsdb.TagSet{}
    25  		tags["disk"] = fmt.Sprint("a", i)
    26  		tags["host"] = fmt.Sprint("b", i)
    27  		if i < 1000 {
    28  			ra.Results = append(ra.Results, &Result{Value: Number(0), Group: tags})
    29  		}
    30  		rb.Results = append(ra.Results, &Result{Value: Number(0), Group: tags})
    31  	}
    32  	return ra, rb
    33  }
    34  
    35  func BenchmarkSlowUnion(b *testing.B) {
    36  	e := State{}
    37  	e.unjoinedOk = true
    38  	ra, rb := buildFakeResults()
    39  	b.ResetTimer()
    40  	for i := 0; i < b.N; i++ {
    41  		e.union(ra, rb, "")
    42  	}
    43  }