mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
core/types: removed CreateBlooms, changed benchmark
This commit is contained in:
parent
80db6321cc
commit
746592bb91
2 changed files with 14 additions and 24 deletions
|
|
@ -115,24 +115,6 @@ func CreateBloom(receipt *Receipt) Bloom {
|
||||||
return bin
|
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
|
// MergeBloom merges the precomputed bloom filters in the Receipts without
|
||||||
// recalculating them. It assumes that each receipt’s Bloom field is already
|
// recalculating them. It assumes that each receipt’s Bloom field is already
|
||||||
// correctly populated.
|
// correctly populated.
|
||||||
|
|
|
||||||
|
|
@ -126,26 +126,32 @@ func BenchmarkCreateBloom(b *testing.B) {
|
||||||
for i := 0; i < 200; i += 2 {
|
for i := 0; i < 200; i += 2 {
|
||||||
copy(rLarge[i:], rSmall)
|
copy(rLarge[i:], rSmall)
|
||||||
}
|
}
|
||||||
b.Run("small", func(b *testing.B) {
|
b.Run("small-createbloom", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
var bl Bloom
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
bl = CreateBlooms(rSmall)
|
for _, receipt := range rSmall {
|
||||||
|
receipt.Bloom = CreateBloom(receipt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
|
bl := MergeBloom(rSmall)
|
||||||
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
||||||
got := crypto.Keccak256Hash(bl.Bytes())
|
got := crypto.Keccak256Hash(bl.Bytes())
|
||||||
if got != exp {
|
if got != exp {
|
||||||
b.Errorf("Got %x, exp %x", 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()
|
b.ReportAllocs()
|
||||||
var bl Bloom
|
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
bl = CreateBlooms(rLarge)
|
for _, receipt := range rLarge {
|
||||||
|
receipt.Bloom = CreateBloom(receipt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
|
bl := MergeBloom(rLarge)
|
||||||
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
||||||
got := crypto.Keccak256Hash(bl.Bytes())
|
got := crypto.Keccak256Hash(bl.Bytes())
|
||||||
if got != exp {
|
if got != exp {
|
||||||
|
|
@ -157,6 +163,7 @@ func BenchmarkCreateBloom(b *testing.B) {
|
||||||
receipt.Bloom = CreateBloom(receipt)
|
receipt.Bloom = CreateBloom(receipt)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
var bl Bloom
|
var bl Bloom
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
|
@ -175,6 +182,7 @@ func BenchmarkCreateBloom(b *testing.B) {
|
||||||
receipt.Bloom = CreateBloom(receipt)
|
receipt.Bloom = CreateBloom(receipt)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
var bl Bloom
|
var bl Bloom
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue