core/types: removed CreateBlooms, changed benchmark

This commit is contained in:
Zsolt Felfoldi 2025-02-13 17:32:24 +01:00
parent 80db6321cc
commit 746592bb91
2 changed files with 14 additions and 24 deletions

View file

@ -115,24 +115,6 @@ func CreateBloom(receipt *Receipt) Bloom {
return bin
}
// CreateBlooms creates a bloom filter out of the give Receipts (+Logs).
// This function is just for benchmarking.
func CreateBlooms(receipts []*Receipt) Bloom {
var (
bin Bloom
buf = make([]byte, 6)
)
for _, receipt := range receipts {
for _, log := range receipt.Logs {
bin.add(log.Address.Bytes(), buf)
for _, b := range log.Topics {
bin.add(b[:], buf)
}
}
}
return bin
}
// MergeBloom merges the precomputed bloom filters in the Receipts without
// recalculating them. It assumes that each receipts Bloom field is already
// correctly populated.

View file

@ -126,26 +126,32 @@ func BenchmarkCreateBloom(b *testing.B) {
for i := 0; i < 200; i += 2 {
copy(rLarge[i:], rSmall)
}
b.Run("small", func(b *testing.B) {
b.Run("small-createbloom", func(b *testing.B) {
b.ReportAllocs()
var bl Bloom
for i := 0; i < b.N; i++ {
bl = CreateBlooms(rSmall)
for _, receipt := range rSmall {
receipt.Bloom = CreateBloom(receipt)
}
}
b.StopTimer()
bl := MergeBloom(rSmall)
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
got := crypto.Keccak256Hash(bl.Bytes())
if got != exp {
b.Errorf("Got %x, exp %x", got, exp)
}
})
b.Run("large", func(b *testing.B) {
b.Run("large-createbloom", func(b *testing.B) {
b.ReportAllocs()
var bl Bloom
for i := 0; i < b.N; i++ {
bl = CreateBlooms(rLarge)
for _, receipt := range rLarge {
receipt.Bloom = CreateBloom(receipt)
}
}
b.StopTimer()
bl := MergeBloom(rLarge)
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
got := crypto.Keccak256Hash(bl.Bytes())
if got != exp {
@ -157,6 +163,7 @@ func BenchmarkCreateBloom(b *testing.B) {
receipt.Bloom = CreateBloom(receipt)
}
b.ReportAllocs()
b.ResetTimer()
var bl Bloom
for i := 0; i < b.N; i++ {
@ -175,6 +182,7 @@ func BenchmarkCreateBloom(b *testing.B) {
receipt.Bloom = CreateBloom(receipt)
}
b.ReportAllocs()
b.ResetTimer()
var bl Bloom
for i := 0; i < b.N; i++ {