write a couple simple benchmarks

This commit is contained in:
whyrusleeping
2019-07-17 23:24:11 -07:00
parent 6e24543e57
commit b7d7f5fb71
2 changed files with 135 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
package types
import (
"math/rand"
"testing"
"github.com/filecoin-project/go-lotus/chain/address"
)
func blsaddr(n int64) address.Address {
buf := make([]byte, 48)
r := rand.New(rand.NewSource(n))
r.Read(buf)
addr, err := address.NewBLSAddress(buf)
if err != nil {
panic(err)
}
return addr
}
func BenchmarkSerializeMessage(b *testing.B) {
m := &Message{
To: blsaddr(1),
From: blsaddr(2),
Nonce: 197,
Method: 1231254,
Params: []byte("some bytes, idk. probably at least ten of them"),
GasLimit: NewInt(126723),
GasPrice: NewInt(1776234),
}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err := m.Serialize()
if err != nil {
b.Fatal(err)
}
}
}