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.

55 lines
1.2 KiB

  1. package mempool
  2. import (
  3. "encoding/binary"
  4. "testing"
  5. "github.com/tendermint/tendermint/abci/example/kvstore"
  6. "github.com/tendermint/tendermint/proxy"
  7. )
  8. func BenchmarkReap(b *testing.B) {
  9. app := kvstore.NewKVStoreApplication()
  10. cc := proxy.NewLocalClientCreator(app)
  11. mempool := newMempoolWithApp(cc)
  12. size := 10000
  13. for i := 0; i < size; i++ {
  14. tx := make([]byte, 8)
  15. binary.BigEndian.PutUint64(tx, uint64(i))
  16. mempool.CheckTx(tx, nil)
  17. }
  18. b.ResetTimer()
  19. for i := 0; i < b.N; i++ {
  20. mempool.ReapMaxBytesMaxGas(100000000, 10000000)
  21. }
  22. }
  23. func BenchmarkCacheInsertTime(b *testing.B) {
  24. cache := newMapTxCache(b.N)
  25. txs := make([][]byte, b.N)
  26. for i := 0; i < b.N; i++ {
  27. txs[i] = make([]byte, 8)
  28. binary.BigEndian.PutUint64(txs[i], uint64(i))
  29. }
  30. b.ResetTimer()
  31. for i := 0; i < b.N; i++ {
  32. cache.Push(txs[i])
  33. }
  34. }
  35. // This benchmark is probably skewed, since we actually will be removing
  36. // txs in parallel, which may cause some overhead due to mutex locking.
  37. func BenchmarkCacheRemoveTime(b *testing.B) {
  38. cache := newMapTxCache(b.N)
  39. txs := make([][]byte, b.N)
  40. for i := 0; i < b.N; i++ {
  41. txs[i] = make([]byte, 8)
  42. binary.BigEndian.PutUint64(txs[i], uint64(i))
  43. cache.Push(txs[i])
  44. }
  45. b.ResetTimer()
  46. for i := 0; i < b.N; i++ {
  47. cache.Remove(txs[i])
  48. }
  49. }