Skip to content

Commit

Permalink
rlp: add big.Int decoder benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed May 22, 2021
1 parent a8c28f2 commit 533b8ba
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions rlp/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"reflect"
"strings"
"testing"

"github.com/ethereum/go-ethereum/common/math"
)

func TestStreamKind(t *testing.T) {
Expand Down Expand Up @@ -1104,8 +1106,28 @@ func BenchmarkDecodeByteArrayStruct(b *testing.B) {

var out byteArrayStruct
for i := 0; i < b.N; i++ {
err := DecodeBytes(enc, &out)
if err != nil {
if err := DecodeBytes(enc, &out); err != nil {
b.Fatal(err)
}
}
}

func BenchmarkDecodeBigInts(b *testing.B) {
ints := make([]*big.Int, 200)
for i := range ints {
ints[i] = math.BigPow(2, int64(i))
}
enc, err := EncodeToBytes(ints)
if err != nil {
b.Fatal(err)
}
b.SetBytes(int64(len(enc)))
b.ReportAllocs()
b.ResetTimer()

var out []*big.Int
for i := 0; i < b.N; i++ {
if err := DecodeBytes(enc, &out); err != nil {
b.Fatal(err)
}
}
Expand Down

0 comments on commit 533b8ba

Please sign in to comment.