Commit e6fdb174 authored by Ubuntu's avatar Ubuntu

fix ethtx benchmark

parent f9f37946
......@@ -10,6 +10,8 @@ import (
"testing"
"time"
"sync"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
......@@ -42,7 +44,12 @@ func (*RingServer) SendRawTransaction(ctx context.Context, req *base.EthTx) (*ri
return &ring.SendRawTransactionResponse{}, nil
}
var once sync.Once
func BenchmarkEthTx(b *testing.B) {
b.ReportAllocs()
onceFunc := func() {
lis, err := net.Listen("tcp", ":9006")
if err != nil {
......@@ -59,8 +66,13 @@ func BenchmarkEthTx(b *testing.B) {
b.Fatal(err)
}
}()
}
b.ReportAllocs()
once.Do(onceFunc)
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
......@@ -75,10 +87,10 @@ func BenchmarkEthTx(b *testing.B) {
local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A")
publicKey := local.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
b.Log(fromAddress)
//publicKey := local.Public()
//publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
//fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
//b.Log(fromAddress)
remote, _ := crypto.GenerateKey()
......@@ -102,9 +114,8 @@ func BenchmarkEthTx(b *testing.B) {
inner.Recipient = &addr
b.RunParallel(func(pb *testing.PB) {
// Each goroutine has its own bytes.Buffer.
for pb.Next() {
// The loop body is executed b.N times total across all goroutines.
res, err := c.SendRawTransaction(ctx, &base.EthTx{Inner: &inner})
......@@ -113,7 +124,9 @@ func BenchmarkEthTx(b *testing.B) {
b.Fatal(err)
}
b.Logf("Greeting: %v\n", res)
_ = res
//b.Logf("Greeting: %v\n", res)
}
})
......@@ -123,3 +136,5 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric
tx, _ := types.SignTx(types.NewTransaction(nonce, to, big.NewInt(100), gaslimit, gasprice, nil), types.HomesteadSigner{}, key)
return tx
}
// go test -bench=.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment