github.com/badrootd/celestia-core@v0.0.0-20240305091328-aa4207a4b25d/mempool/cat/pool_bench_test.go (about)

     1  package cat
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     6  	"testing"
     7  	"time"
     8  
     9  	"github.com/badrootd/celestia-core/mempool"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func BenchmarkTxPool_CheckTx(b *testing.B) {
    14  	txmp := setup(b, 10000)
    15  	txmp.config.Size = b.N
    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("sender%d=%X=%d", n, prefix, priority))
    28  		b.StartTimer()
    29  
    30  		require.NoError(b, txmp.CheckTx(tx, nil, mempool.TxInfo{}))
    31  	}
    32  }