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
792 B

  1. package mempool
  2. import (
  3. "encoding/binary"
  4. "testing"
  5. )
  6. func BenchmarkCacheInsertTime(b *testing.B) {
  7. cache := NewLRUTxCache(b.N)
  8. txs := make([][]byte, b.N)
  9. for i := 0; i < b.N; i++ {
  10. txs[i] = make([]byte, 8)
  11. binary.BigEndian.PutUint64(txs[i], uint64(i))
  12. }
  13. b.ResetTimer()
  14. for i := 0; i < b.N; i++ {
  15. cache.Push(txs[i])
  16. }
  17. }
  18. // This benchmark is probably skewed, since we actually will be removing
  19. // txs in parallel, which may cause some overhead due to mutex locking.
  20. func BenchmarkCacheRemoveTime(b *testing.B) {
  21. cache := NewLRUTxCache(b.N)
  22. txs := make([][]byte, b.N)
  23. for i := 0; i < b.N; i++ {
  24. txs[i] = make([]byte, 8)
  25. binary.BigEndian.PutUint64(txs[i], uint64(i))
  26. cache.Push(txs[i])
  27. }
  28. b.ResetTimer()
  29. for i := 0; i < b.N; i++ {
  30. cache.Remove(txs[i])
  31. }
  32. }