mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
add a benchmark test for list.Cap
This commit is contained in:
parent
dce9c0c369
commit
d5ae16c486
1 changed files with 22 additions and 0 deletions
|
|
@ -70,3 +70,25 @@ func BenchmarkListAdd(b *testing.B) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkListCapOneTx(b *testing.B) {
|
||||
// Generate a list of transactions to insert
|
||||
key, _ := crypto.GenerateKey()
|
||||
|
||||
txs := make(types.Transactions, 32)
|
||||
for i := 0; i < len(txs); i++ {
|
||||
txs[i] = transaction(uint64(i), 0, key)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
list := newList(true)
|
||||
// Insert the transactions in a random order
|
||||
for _, v := range rand.Perm(len(txs)) {
|
||||
list.Add(txs[v], DefaultConfig.PriceBump)
|
||||
}
|
||||
b.StartTimer()
|
||||
list.Cap(list.Len() - 1)
|
||||
b.StopTimer()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue