github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/internal/pubsub/query/bench_test.go (about)

     1  package query_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/ari-anchor/sei-tendermint/abci/types"
     7  	"github.com/ari-anchor/sei-tendermint/internal/pubsub/query"
     8  )
     9  
    10  const testQuery = `tm.events.type='NewBlock' AND abci.account.name='Igor'`
    11  
    12  var testEvents = []types.Event{
    13  	{
    14  		Type: "tm.events",
    15  		Attributes: []types.EventAttribute{{
    16  			Key:   []byte("index"),
    17  			Value: []byte("25"),
    18  		}, {
    19  			Key:   []byte("type"),
    20  			Value: []byte("NewBlock"),
    21  		}},
    22  	},
    23  	{
    24  		Type: "abci.account",
    25  		Attributes: []types.EventAttribute{{
    26  			Key:   []byte("name"),
    27  			Value: []byte("Anya"),
    28  		}, {
    29  			Key:   []byte("name"),
    30  			Value: []byte("Igor"),
    31  		}},
    32  	},
    33  }
    34  
    35  func BenchmarkParseCustom(b *testing.B) {
    36  	for i := 0; i < b.N; i++ {
    37  		_, err := query.New(testQuery)
    38  		if err != nil {
    39  			b.Fatal(err)
    40  		}
    41  	}
    42  }
    43  
    44  func BenchmarkMatchCustom(b *testing.B) {
    45  	q, err := query.New(testQuery)
    46  	if err != nil {
    47  		b.Fatal(err)
    48  	}
    49  	b.ResetTimer()
    50  	for i := 0; i < b.N; i++ {
    51  		if !q.Matches(testEvents) {
    52  			b.Error("no match")
    53  		}
    54  	}
    55  }