add a benchmark test for list.Cap

This commit is contained in:
colinlyguo 2024-02-13 19:09:44 +08:00
parent dce9c0c369
commit d5ae16c486
No known key found for this signature in database
GPG key ID: 82E123BE1B68288B

View file

@ -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()
}
}