github.com/noirx94/tendermintmp@v0.0.1/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 if err := mempool.CheckTx(tx, nil, TxInfo{}); err != nil { 22 b.Error(err) 23 } 24 } 25 b.ResetTimer() 26 for i := 0; i < b.N; i++ { 27 mempool.ReapMaxBytesMaxGas(100000000, 10000000) 28 } 29 } 30 31 func BenchmarkCheckTx(b *testing.B) { 32 app := kvstore.NewApplication() 33 cc := proxy.NewLocalClientCreator(app) 34 mempool, cleanup := newMempoolWithApp(cc) 35 defer cleanup() 36 37 for i := 0; i < b.N; i++ { 38 tx := make([]byte, 8) 39 binary.BigEndian.PutUint64(tx, uint64(i)) 40 if err := mempool.CheckTx(tx, nil, TxInfo{}); err != nil { 41 b.Error(err) 42 } 43 } 44 } 45 46 func BenchmarkCacheInsertTime(b *testing.B) { 47 cache := newMapTxCache(b.N) 48 txs := make([][]byte, b.N) 49 for i := 0; i < b.N; i++ { 50 txs[i] = make([]byte, 8) 51 binary.BigEndian.PutUint64(txs[i], uint64(i)) 52 } 53 b.ResetTimer() 54 for i := 0; i < b.N; i++ { 55 cache.Push(txs[i]) 56 } 57 } 58 59 // This benchmark is probably skewed, since we actually will be removing 60 // txs in parallel, which may cause some overhead due to mutex locking. 61 func BenchmarkCacheRemoveTime(b *testing.B) { 62 cache := newMapTxCache(b.N) 63 txs := make([][]byte, b.N) 64 for i := 0; i < b.N; i++ { 65 txs[i] = make([]byte, 8) 66 binary.BigEndian.PutUint64(txs[i], uint64(i)) 67 cache.Push(txs[i]) 68 } 69 b.ResetTimer() 70 for i := 0; i < b.N; i++ { 71 cache.Remove(txs[i]) 72 } 73 }