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