mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-15 12:36:48 +00:00
core/types: using testing.B.Loop (#32643)
before: go test -run=^$ -bench=. ./core/types 47.80s user 2.18s system 102% cpu 48.936 tota after: go test -run=^$ -bench=. ./core/types 42.42s user 2.27s system 112% cpu 39.593 total
This commit is contained in:
parent
79a4f76b03
commit
e35c628656
5 changed files with 15 additions and 21 deletions
|
|
@ -263,9 +263,8 @@ var benchBuffer = bytes.NewBuffer(make([]byte, 0, 32000))
|
||||||
|
|
||||||
func BenchmarkEncodeBlock(b *testing.B) {
|
func BenchmarkEncodeBlock(b *testing.B) {
|
||||||
block := makeBenchBlock()
|
block := makeBenchBlock()
|
||||||
b.ResetTimer()
|
|
||||||
|
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
benchBuffer.Reset()
|
benchBuffer.Reset()
|
||||||
if err := rlp.Encode(benchBuffer, block); err != nil {
|
if err := rlp.Encode(benchBuffer, block); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ func TestBloomExtensively(t *testing.T) {
|
||||||
|
|
||||||
func BenchmarkBloom9(b *testing.B) {
|
func BenchmarkBloom9(b *testing.B) {
|
||||||
test := []byte("testestestest")
|
test := []byte("testestestest")
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
Bloom9(test)
|
Bloom9(test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +86,7 @@ func BenchmarkBloom9(b *testing.B) {
|
||||||
func BenchmarkBloom9Lookup(b *testing.B) {
|
func BenchmarkBloom9Lookup(b *testing.B) {
|
||||||
toTest := []byte("testtest")
|
toTest := []byte("testtest")
|
||||||
bloom := new(Bloom)
|
bloom := new(Bloom)
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
bloom.Test(toTest)
|
bloom.Test(toTest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +128,7 @@ func BenchmarkCreateBloom(b *testing.B) {
|
||||||
}
|
}
|
||||||
b.Run("small-createbloom", func(b *testing.B) {
|
b.Run("small-createbloom", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
for _, receipt := range rSmall {
|
for _, receipt := range rSmall {
|
||||||
receipt.Bloom = CreateBloom(receipt)
|
receipt.Bloom = CreateBloom(receipt)
|
||||||
}
|
}
|
||||||
|
|
@ -144,7 +144,7 @@ func BenchmarkCreateBloom(b *testing.B) {
|
||||||
})
|
})
|
||||||
b.Run("large-createbloom", func(b *testing.B) {
|
b.Run("large-createbloom", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
for _, receipt := range rLarge {
|
for _, receipt := range rLarge {
|
||||||
receipt.Bloom = CreateBloom(receipt)
|
receipt.Bloom = CreateBloom(receipt)
|
||||||
}
|
}
|
||||||
|
|
@ -163,13 +163,11 @@ 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 b.Loop() {
|
||||||
bl = MergeBloom(rSmall)
|
bl = MergeBloom(rSmall)
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
|
||||||
|
|
||||||
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
||||||
got := crypto.Keccak256Hash(bl.Bytes())
|
got := crypto.Keccak256Hash(bl.Bytes())
|
||||||
|
|
@ -182,13 +180,11 @@ 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 b.Loop() {
|
||||||
bl = MergeBloom(rLarge)
|
bl = MergeBloom(rLarge)
|
||||||
}
|
}
|
||||||
b.StopTimer()
|
|
||||||
|
|
||||||
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
var exp = common.HexToHash("c384c56ece49458a427c67b90fefe979ebf7104795be65dc398b280f24104949")
|
||||||
got := crypto.Keccak256Hash(bl.Bytes())
|
got := crypto.Keccak256Hash(bl.Bytes())
|
||||||
|
|
|
||||||
|
|
@ -84,9 +84,8 @@ func BenchmarkDeriveSha200(b *testing.B) {
|
||||||
var exp common.Hash
|
var exp common.Hash
|
||||||
var got common.Hash
|
var got common.Hash
|
||||||
b.Run("std_trie", func(b *testing.B) {
|
b.Run("std_trie", func(b *testing.B) {
|
||||||
b.ResetTimer()
|
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
exp = types.DeriveSha(txs, trie.NewEmpty(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)))
|
exp = types.DeriveSha(txs, trie.NewEmpty(triedb.NewDatabase(rawdb.NewMemoryDatabase(), nil)))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -94,7 +93,7 @@ func BenchmarkDeriveSha200(b *testing.B) {
|
||||||
b.Run("stack_trie", func(b *testing.B) {
|
b.Run("stack_trie", func(b *testing.B) {
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
got = types.DeriveSha(txs, trie.NewStackTrie(nil))
|
got = types.DeriveSha(txs, trie.NewStackTrie(nil))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -591,7 +591,7 @@ func BenchmarkHash(b *testing.B) {
|
||||||
GasTipCap: big.NewInt(500),
|
GasTipCap: big.NewInt(500),
|
||||||
GasFeeCap: big.NewInt(500),
|
GasFeeCap: big.NewInt(500),
|
||||||
})
|
})
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
signer.Hash(tx)
|
signer.Hash(tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -614,7 +614,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
|
||||||
|
|
||||||
b.Run("Original", func(b *testing.B) {
|
b.Run("Original", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
_, err := tx.EffectiveGasTip(baseFee.ToBig())
|
_, err := tx.EffectiveGasTip(baseFee.ToBig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
@ -625,7 +625,7 @@ func BenchmarkEffectiveGasTip(b *testing.B) {
|
||||||
b.Run("IntoMethod", func(b *testing.B) {
|
b.Run("IntoMethod", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
dst := new(uint256.Int)
|
dst := new(uint256.Int)
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
err := tx.calcEffectiveGasTip(dst, baseFee)
|
err := tx.calcEffectiveGasTip(dst, baseFee)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
|
@ -729,7 +729,7 @@ func BenchmarkEffectiveGasTipCmp(b *testing.B) {
|
||||||
|
|
||||||
b.Run("Original", func(b *testing.B) {
|
b.Run("Original", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
tx.EffectiveGasTipCmp(other, baseFee)
|
tx.EffectiveGasTipCmp(other, baseFee)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ func benchRLP(b *testing.B, encode bool) {
|
||||||
b.Run(tc.name, func(b *testing.B) {
|
b.Run(tc.name, func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
var null = &devnull{}
|
var null = &devnull{}
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
rlp.Encode(null, tc.obj)
|
rlp.Encode(null, tc.obj)
|
||||||
}
|
}
|
||||||
b.SetBytes(int64(null.len / b.N))
|
b.SetBytes(int64(null.len / b.N))
|
||||||
|
|
@ -136,7 +136,7 @@ func benchRLP(b *testing.B, encode bool) {
|
||||||
// Test decoding
|
// Test decoding
|
||||||
b.Run(tc.name, func(b *testing.B) {
|
b.Run(tc.name, func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for b.Loop() {
|
||||||
if err := rlp.DecodeBytes(data, tc.obj); err != nil {
|
if err := rlp.DecodeBytes(data, tc.obj); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue