github.com/okex/exchain@v1.8.0/libs/tendermint/mempool/bench_test.go (about)

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