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.

56 lines
1.3 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, cleanup := newMempoolWithApp(cc)
  12. defer cleanup()
  13. size := 10000
  14. for i := 0; i < size; i++ {
  15. tx := make([]byte, 8)
  16. binary.BigEndian.PutUint64(tx, uint64(i))
  17. mempool.CheckTx(tx, nil)
  18. }
  19. b.ResetTimer()
  20. for i := 0; i < b.N; i++ {
  21. mempool.ReapMaxBytesMaxGas(100000000, 10000000)
  22. }
  23. }
  24. func BenchmarkCacheInsertTime(b *testing.B) {
  25. cache := newMapTxCache(b.N)
  26. txs := make([][]byte, b.N)
  27. for i := 0; i < b.N; i++ {
  28. txs[i] = make([]byte, 8)
  29. binary.BigEndian.PutUint64(txs[i], uint64(i))
  30. }
  31. b.ResetTimer()
  32. for i := 0; i < b.N; i++ {
  33. cache.Push(txs[i])
  34. }
  35. }
  36. // This benchmark is probably skewed, since we actually will be removing
  37. // txs in parallel, which may cause some overhead due to mutex locking.
  38. func BenchmarkCacheRemoveTime(b *testing.B) {
  39. cache := newMapTxCache(b.N)
  40. txs := make([][]byte, b.N)
  41. for i := 0; i < b.N; i++ {
  42. txs[i] = make([]byte, 8)
  43. binary.BigEndian.PutUint64(txs[i], uint64(i))
  44. cache.Push(txs[i])
  45. }
  46. b.ResetTimer()
  47. for i := 0; i < b.N; i++ {
  48. cache.Remove(txs[i])
  49. }
  50. }