github.com/MagHErmit/tendermint@v0.282.1/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/MagHErmit/tendermint/mempool"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func BenchmarkTxMempool_CheckTx(b *testing.B) {
    14  	txmp := setup(b, 10000)
    15  	rng := rand.New(rand.NewSource(time.Now().UnixNano()))
    16  
    17  	b.ResetTimer()
    18  
    19  	for n := 0; n < b.N; n++ {
    20  		b.StopTimer()
    21  		prefix := make([]byte, 20)
    22  		_, err := rng.Read(prefix)
    23  		require.NoError(b, err)
    24  
    25  		priority := int64(rng.Intn(9999-1000) + 1000)
    26  		tx := []byte(fmt.Sprintf("%X=%d", prefix, priority))
    27  		b.StartTimer()
    28  
    29  		require.NoError(b, txmp.CheckTx(tx, nil, mempool.TxInfo{}))
    30  	}
    31  }