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.

41 lines
927 B

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