github.com/pokt-network/tendermint@v0.32.11-0.20230426215212-59310158d3e9/mempool/bench_test.go (about)

     1  package mempool
     2  
     3  import (
     4  	"encoding/binary"
     5  	"testing"
     6  
     7  	"github.com/tendermint/tendermint/abci/example/kvstore"
     8  	"github.com/tendermint/tendermint/proxy"
     9  )
    10  
    11  func BenchmarkReap(b *testing.B) {
    12  	app := kvstore.NewApplication()
    13  	cc := proxy.NewLocalClientCreator(app)
    14  	mempool, cleanup := newMempoolWithApp(cc)
    15  	defer cleanup()
    16  
    17  	size := 10000
    18  	for i := 0; i < size; i++ {
    19  		tx := make([]byte, 8)
    20  		binary.BigEndian.PutUint64(tx, uint64(i))
    21  		mempool.CheckTx(tx, nil, TxInfo{})
    22  	}
    23  	b.ResetTimer()
    24  	for i := 0; i < b.N; i++ {
    25  		mempool.ReapMaxBytesMaxGas(100000000, 10000000)
    26  	}
    27  }
    28  
    29  func BenchmarkCheckTx(b *testing.B) {
    30  	app := kvstore.NewApplication()
    31  	cc := proxy.NewLocalClientCreator(app)
    32  	mempool, cleanup := newMempoolWithApp(cc)
    33  	defer cleanup()
    34  
    35  	for i := 0; i < b.N; i++ {
    36  		tx := make([]byte, 8)
    37  		binary.BigEndian.PutUint64(tx, uint64(i))
    38  		mempool.CheckTx(tx, nil, TxInfo{})
    39  	}
    40  }
    41  
    42  func BenchmarkCacheInsertTime(b *testing.B) {
    43  	cache := newMapTxCache(b.N)
    44  	txs := make([][]byte, b.N)
    45  	for i := 0; i < b.N; i++ {
    46  		txs[i] = make([]byte, 8)
    47  		binary.BigEndian.PutUint64(txs[i], uint64(i))
    48  	}
    49  	b.ResetTimer()
    50  	for i := 0; i < b.N; i++ {
    51  		cache.Push(txs[i])
    52  	}
    53  }
    54  
    55  // This benchmark is probably skewed, since we actually will be removing
    56  // txs in parallel, which may cause some overhead due to mutex locking.
    57  func BenchmarkCacheRemoveTime(b *testing.B) {
    58  	cache := newMapTxCache(b.N)
    59  	txs := make([][]byte, b.N)
    60  	for i := 0; i < b.N; i++ {
    61  		txs[i] = make([]byte, 8)
    62  		binary.BigEndian.PutUint64(txs[i], uint64(i))
    63  		cache.Push(txs[i])
    64  	}
    65  	b.ResetTimer()
    66  	for i := 0; i < b.N; i++ {
    67  		cache.Remove(txs[i])
    68  	}
    69  }