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.

34 lines
659 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. txmp := setup(ctx, b, 10000)
  14. rng := rand.New(rand.NewSource(time.Now().UnixNano()))
  15. b.ResetTimer()
  16. for n := 0; n < b.N; n++ {
  17. b.StopTimer()
  18. prefix := make([]byte, 20)
  19. _, err := rng.Read(prefix)
  20. require.NoError(b, err)
  21. priority := int64(rng.Intn(9999-1000) + 1000)
  22. tx := []byte(fmt.Sprintf("%X=%d", prefix, priority))
  23. b.StartTimer()
  24. require.NoError(b, txmp.CheckTx(ctx, tx, nil, TxInfo{}))
  25. }
  26. }