rlp: fix Decode benchmarks

This commit is contained in:
Felix Lange 2015-01-15 11:12:39 +01:00
parent 552f5b2693
commit 29c46cdf34

View File

@ -8,8 +8,6 @@ import (
"math/big" "math/big"
"reflect" "reflect"
"testing" "testing"
"github.com/ethereum/go-ethereum/ethutil"
) )
func TestStreamKind(t *testing.T) { func TestStreamKind(t *testing.T) {
@ -515,7 +513,7 @@ func BenchmarkDecode(b *testing.B) {
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
var s []int var s []uint
r := bytes.NewReader(enc) r := bytes.NewReader(enc)
if err := Decode(r, &s); err != nil { if err := Decode(r, &s); err != nil {
b.Fatalf("Decode error: %v", err) b.Fatalf("Decode error: %v", err)
@ -529,7 +527,7 @@ func BenchmarkDecodeIntSliceReuse(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()
var s []int var s []uint
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
r := bytes.NewReader(enc) r := bytes.NewReader(enc)
if err := Decode(r, &s); err != nil { if err := Decode(r, &s); err != nil {
@ -538,12 +536,16 @@ func BenchmarkDecodeIntSliceReuse(b *testing.B) {
} }
} }
func encodeTestSlice(n int) []byte { func encodeTestSlice(n uint) []byte {
s := make([]interface{}, n) s := make([]uint, n)
for i := 0; i < n; i++ { for i := uint(0); i < n; i++ {
s[i] = i s[i] = i
} }
return ethutil.Encode(s) b, err := EncodeToBytes(s)
if err != nil {
panic(fmt.Sprintf("encode error: %v", err))
}
return b
} }
func unhex(str string) []byte { func unhex(str string) []byte {