You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

  1. package mempool
  2. import (
  3. "context"
  4. "fmt"
  5. "math/rand"
  6. "testing"
  7. "time"
  8. "github.com/stretchr/testify/require"
  9. abciclient "github.com/tendermint/tendermint/abci/client"
  10. "github.com/tendermint/tendermint/abci/example/kvstore"
  11. "github.com/tendermint/tendermint/libs/log"
  12. )
  13. func BenchmarkTxMempool_CheckTx(b *testing.B) {
  14. ctx, cancel := context.WithCancel(context.Background())
  15. defer cancel()
  16. client := abciclient.NewLocalClient(log.NewNopLogger(), kvstore.NewApplication())
  17. if err := client.Start(ctx); err != nil {
  18. b.Fatal(err)
  19. }
  20. // setup the cache and the mempool number for hitting GetEvictableTxs during the
  21. // benchmark. 5000 is the current default mempool size in the TM config.
  22. txmp := setup(ctx, b, client, 10000)
  23. txmp.config.Size = 5000
  24. rng := rand.New(rand.NewSource(time.Now().UnixNano()))
  25. const peerID = 1
  26. b.ResetTimer()
  27. for n := 0; n < b.N; n++ {
  28. b.StopTimer()
  29. prefix := make([]byte, 20)
  30. _, err := rng.Read(prefix)
  31. require.NoError(b, err)
  32. priority := int64(rng.Intn(9999-1000) + 1000)
  33. tx := []byte(fmt.Sprintf("sender-%d-%d=%X=%d", n, peerID, prefix, priority))
  34. txInfo := TxInfo{SenderID: uint16(peerID)}
  35. b.StartTimer()
  36. require.NoError(b, txmp.CheckTx(ctx, tx, nil, txInfo))
  37. }
  38. }