github.com/vipernet-xyz/tm@v0.34.24/mempool/v1/mempool_bench_test.go (about)

     1  package v1
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/stretchr/testify/require"
    10  
    11  	"github.com/vipernet-xyz/tm/mempool"
    12  )
    13  
    14  func BenchmarkTxMempool_CheckTx(b *testing.B) {
    15  	txmp := setup(b, 10000)
    16  	rng := rand.New(rand.NewSource(time.Now().UnixNano()))
    17  
    18  	b.ResetTimer()
    19  
    20  	for n := 0; n < b.N; n++ {
    21  		b.StopTimer()
    22  		prefix := make([]byte, 20)
    23  		_, err := rng.Read(prefix)
    24  		require.NoError(b, err)
    25  
    26  		priority := int64(rng.Intn(9999-1000) + 1000)
    27  		tx := []byte(fmt.Sprintf("%X=%d", prefix, priority))
    28  		b.StartTimer()
    29  
    30  		require.NoError(b, txmp.CheckTx(tx, nil, mempool.TxInfo{}))
    31  	}
    32  }