Commit 71bb6705 authored by Ubuntu's avatar Ubuntu

update go test

parent 83e05cc4
...@@ -25,11 +25,10 @@ import ( ...@@ -25,11 +25,10 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
// func BenchmarkFib10(b *testing.B) { var countParallelAsEth int64
// for n := 0; n < b.N; n++ { var countParallelAsStd int64
// //Fib(10) var countParallelAsAny int64
// } var countParallelAsBytes int64
// }
type RingServer struct { type RingServer struct {
ring.UnimplementedRingServiceServer ring.UnimplementedRingServiceServer
...@@ -37,8 +36,6 @@ type RingServer struct { ...@@ -37,8 +36,6 @@ type RingServer struct {
func (*RingServer) SendTxAsEth(ctx context.Context, in *base.TransactionEth) (*ring.SendRawTransactionResponse, error) { func (*RingServer) SendTxAsEth(ctx context.Context, in *base.TransactionEth) (*ring.SendRawTransactionResponse, error) {
//fmt.Println(in.Tx.Inner.Recipient)
addr := common.Address{} addr := common.Address{}
copy(addr[:], in.Tx.Inner.Recipient.Address[:common.AddressLength]) copy(addr[:], in.Tx.Inner.Recipient.Address[:common.AddressLength])
...@@ -55,6 +52,9 @@ func (*RingServer) SendTxAsEth(ctx context.Context, in *base.TransactionEth) (*r ...@@ -55,6 +52,9 @@ func (*RingServer) SendTxAsEth(ctx context.Context, in *base.TransactionEth) (*r
S: new(big.Int).SetBytes(in.Tx.Inner.S), S: new(big.Int).SetBytes(in.Tx.Inner.S),
}) })
// atomic.AddInt64(&countParallelAsEth, 1)
// defer fmt.Println("countParallelAsEth", countParallelAsEth)
return &ring.SendRawTransactionResponse{TxHash: ethTx.Hash().Bytes()}, nil return &ring.SendRawTransactionResponse{TxHash: ethTx.Hash().Bytes()}, nil
} }
...@@ -76,6 +76,10 @@ func (*RingServer) SendTxAsStd(ctx context.Context, in *base.TransactionStd) (*r ...@@ -76,6 +76,10 @@ func (*RingServer) SendTxAsStd(ctx context.Context, in *base.TransactionStd) (*r
S: new(big.Int).SetBytes(in.Tx.Inner.S), S: new(big.Int).SetBytes(in.Tx.Inner.S),
}) })
// atomic.AddInt64(&countParallelAsStd, 1)
// defer fmt.Println("countParallelAsStd", countParallelAsStd)
return &ring.SendRawTransactionResponse{TxHash: ethTx.Hash().Bytes()}, nil return &ring.SendRawTransactionResponse{TxHash: ethTx.Hash().Bytes()}, nil
} }
...@@ -87,6 +91,9 @@ func (*RingServer) SendTxAsAny(ctx context.Context, in *base.Transaction) (*ring ...@@ -87,6 +91,9 @@ func (*RingServer) SendTxAsAny(ctx context.Context, in *base.Transaction) (*ring
return nil, err return nil, err
} }
// atomic.AddInt64(&countParallelAsAny, 1)
// defer fmt.Println("countParallelAsAny", countParallelAsAny)
switch m := msg.(type) { switch m := msg.(type) {
case *base.EthTx: case *base.EthTx:
...@@ -142,6 +149,9 @@ func (*RingServer) SendTxAsBytes(ctx context.Context, in *base.TransactionBytes) ...@@ -142,6 +149,9 @@ func (*RingServer) SendTxAsBytes(ctx context.Context, in *base.TransactionBytes)
return nil, err return nil, err
} }
// atomic.AddInt64(&countParallelAsBytes, 1)
// defer fmt.Printf("countParallelAsBytes: %d\n", countParallelAsBytes)
return &ring.SendRawTransactionResponse{TxHash: ethTx.Hash().Bytes()}, nil return &ring.SendRawTransactionResponse{TxHash: ethTx.Hash().Bytes()}, nil
} }
...@@ -178,6 +188,21 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric ...@@ -178,6 +188,21 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=1s // go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=1s
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=1s // go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=1s
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=1x
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=1x
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=1x
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=1x
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=100x
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=100x
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=100x
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=100x
// go test -v -run BenchmarkEthTx -bench BenchmarkEthTx -benchtime=100x -benchmem
// go test -v -run BenchmarkStdTx -bench BenchmarkStdTx -benchtime=100x -benchmem
// go test -v -run BenchmarkAnyTx -bench BenchmarkAnyTx -benchtime=100x -benchmem
// go test -v -run BenchmarkBytesEth -bench BenchmarkBytesEth -benchtime=100x -benchmem
// go test -v -run TestGrpcServer -timeout 0 // go test -v -run TestGrpcServer -timeout 0
//BenchmarkAny //BenchmarkAny
...@@ -210,15 +235,10 @@ var onceHash sync.Once ...@@ -210,15 +235,10 @@ var onceHash sync.Once
func BenchmarkEthTx(b *testing.B) { func BenchmarkEthTx(b *testing.B) {
// count++ b.Logf("b.N: %d\n", b.N)
// defer fmt.Println("defer countParallel", countParallel)
// defer fmt.Println("defer count", count)
// defer fmt.Println("defer b.N", b.N)
onceFunc := func() { onceFunc := func() {
//fmt.Println("once b.N", b.N)
local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A") local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A")
publicKey := local.Public() publicKey := local.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey) publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
...@@ -230,15 +250,11 @@ func BenchmarkEthTx(b *testing.B) { ...@@ -230,15 +250,11 @@ func BenchmarkEthTx(b *testing.B) {
once.Do(onceFunc) once.Do(onceFunc)
b.ReportAllocs() b.ResetTimer()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
//countParallel++
for pb.Next() { for pb.Next() {
//for i := 0; i < b.N; i++ { //串行
conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials())) conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -284,17 +300,15 @@ func BenchmarkEthTx(b *testing.B) { ...@@ -284,17 +300,15 @@ func BenchmarkEthTx(b *testing.B) {
onceHash.Do(func() { onceHash.Do(func() {
b.Logf("response: %x local: %x \n", res.TxHash, tx.Hash().Bytes()) b.Logf("response: %x local: %x \n", res.TxHash, tx.Hash().Bytes())
}) })
//fmt.Printf("%x \n", res.TxHash)
} }
}) })
//}
} }
func BenchmarkStdTx(b *testing.B) { func BenchmarkStdTx(b *testing.B) {
b.Logf("b.N: %d\n", b.N)
onceFunc := func() { onceFunc := func() {
local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A") local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A")
publicKey := local.Public() publicKey := local.Public()
...@@ -307,7 +321,7 @@ func BenchmarkStdTx(b *testing.B) { ...@@ -307,7 +321,7 @@ func BenchmarkStdTx(b *testing.B) {
once.Do(onceFunc) once.Do(onceFunc)
b.ReportAllocs() b.ResetTimer()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
...@@ -377,7 +391,7 @@ func BenchmarkAnyTx(b *testing.B) { ...@@ -377,7 +391,7 @@ func BenchmarkAnyTx(b *testing.B) {
once.Do(onceFunc) once.Do(onceFunc)
b.ReportAllocs() b.ResetTimer()
// The loop body is executed b.N times total across all goroutines. // The loop body is executed b.N times total across all goroutines.
...@@ -452,7 +466,7 @@ func BenchmarkBytesEth(b *testing.B) { ...@@ -452,7 +466,7 @@ func BenchmarkBytesEth(b *testing.B) {
once.Do(onceFunc) once.Do(onceFunc)
b.ReportAllocs() b.ResetTimer()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
...@@ -539,14 +553,6 @@ func TestAnyTx(t *testing.T) { ...@@ -539,14 +553,6 @@ func TestAnyTx(t *testing.T) {
once.Do(onceFunc) once.Do(onceFunc)
// b.ReportAllocs()
// // The loop body is executed b.N times total across all goroutines.
// b.RunParallel(func(pb *testing.PB) {
// for pb.Next() {
conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials())) conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -634,6 +640,13 @@ func TestAnyTx(t *testing.T) { ...@@ -634,6 +640,13 @@ func TestAnyTx(t *testing.T) {
_ = res _ = res
// } }
// })
//go test -v -run BenchmarkHello -bench BenchmarkHello -benchtime=3s
func BenchmarkHello(b *testing.B) {
b.Log(b.N)
for i := 0; i < b.N; i++ {
fmt.Sprintf("hello")
}
} }
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