github.com/MagHErmit/tendermint@v0.282.1/mempool/v0/bench_test.go (about) 1 package v0 2 3 import ( 4 "encoding/binary" 5 "sync/atomic" 6 "testing" 7 8 "github.com/MagHErmit/tendermint/abci/example/kvstore" 9 "github.com/MagHErmit/tendermint/mempool" 10 "github.com/MagHErmit/tendermint/proxy" 11 ) 12 13 func BenchmarkReap(b *testing.B) { 14 app := kvstore.NewApplication() 15 cc := proxy.NewLocalClientCreator(app) 16 mp, cleanup := newMempoolWithApp(cc) 17 defer cleanup() 18 19 mp.config.Size = 100000 20 21 size := 10000 22 for i := 0; i < size; i++ { 23 tx := make([]byte, 8) 24 binary.BigEndian.PutUint64(tx, uint64(i)) 25 if err := mp.CheckTx(tx, nil, mempool.TxInfo{}); err != nil { 26 b.Fatal(err) 27 } 28 } 29 b.ResetTimer() 30 for i := 0; i < b.N; i++ { 31 mp.ReapMaxBytesMaxGas(100000000, 10000000) 32 } 33 } 34 35 func BenchmarkCheckTx(b *testing.B) { 36 app := kvstore.NewApplication() 37 cc := proxy.NewLocalClientCreator(app) 38 mp, cleanup := newMempoolWithApp(cc) 39 defer cleanup() 40 41 mp.config.Size = 1000000 42 43 b.ResetTimer() 44 45 for i := 0; i < b.N; i++ { 46 b.StopTimer() 47 tx := make([]byte, 8) 48 binary.BigEndian.PutUint64(tx, uint64(i)) 49 b.StartTimer() 50 51 if err := mp.CheckTx(tx, nil, mempool.TxInfo{}); err != nil { 52 b.Fatal(err) 53 } 54 } 55 } 56 57 func BenchmarkParallelCheckTx(b *testing.B) { 58 app := kvstore.NewApplication() 59 cc := proxy.NewLocalClientCreator(app) 60 mp, cleanup := newMempoolWithApp(cc) 61 defer cleanup() 62 63 mp.config.Size = 100000000 64 65 var txcnt uint64 66 next := func() uint64 { 67 return atomic.AddUint64(&txcnt, 1) - 1 68 } 69 70 b.ResetTimer() 71 b.RunParallel(func(pb *testing.PB) { 72 for pb.Next() { 73 tx := make([]byte, 8) 74 binary.BigEndian.PutUint64(tx, next()) 75 if err := mp.CheckTx(tx, nil, mempool.TxInfo{}); err != nil { 76 b.Fatal(err) 77 } 78 } 79 }) 80 } 81 82 func BenchmarkCheckDuplicateTx(b *testing.B) { 83 app := kvstore.NewApplication() 84 cc := proxy.NewLocalClientCreator(app) 85 mp, cleanup := newMempoolWithApp(cc) 86 defer cleanup() 87 88 mp.config.Size = 1000000 89 90 for i := 0; i < b.N; i++ { 91 tx := make([]byte, 8) 92 binary.BigEndian.PutUint64(tx, uint64(i)) 93 if err := mp.CheckTx(tx, nil, mempool.TxInfo{}); err != nil { 94 b.Fatal(err) 95 } 96 97 if err := mp.CheckTx(tx, nil, mempool.TxInfo{}); err == nil { 98 b.Fatal("tx should be duplicate") 99 } 100 } 101 }