Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MetaProtocol
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nebula
MetaProtocol
Commits
71bb6705
Commit
71bb6705
authored
Dec 01, 2022
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update go test
parent
83e05cc4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
35 deletions
+48
-35
grcp-tx_test.go
grcp-tx_test.go
+48
-35
No files found.
grcp-tx_test.go
View file @
71bb6705
...
...
@@ -25,11 +25,10 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
// func BenchmarkFib10(b *testing.B) {
// for n := 0; n < b.N; n++ {
// //Fib(10)
// }
// }
var
countParallelAsEth
int64
var
countParallelAsStd
int64
var
countParallelAsAny
int64
var
countParallelAsBytes
int64
type
RingServer
struct
{
ring
.
UnimplementedRingServiceServer
...
...
@@ -37,8 +36,6 @@ type RingServer struct {
func
(
*
RingServer
)
SendTxAsEth
(
ctx
context
.
Context
,
in
*
base
.
TransactionEth
)
(
*
ring
.
SendRawTransactionResponse
,
error
)
{
//fmt.Println(in.Tx.Inner.Recipient)
addr
:=
common
.
Address
{}
copy
(
addr
[
:
],
in
.
Tx
.
Inner
.
Recipient
.
Address
[
:
common
.
AddressLength
])
...
...
@@ -55,6 +52,9 @@ func (*RingServer) SendTxAsEth(ctx context.Context, in *base.TransactionEth) (*r
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
}
...
...
@@ -76,6 +76,10 @@ func (*RingServer) SendTxAsStd(ctx context.Context, in *base.TransactionStd) (*r
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
}
...
...
@@ -87,6 +91,9 @@ func (*RingServer) SendTxAsAny(ctx context.Context, in *base.Transaction) (*ring
return
nil
,
err
}
// atomic.AddInt64(&countParallelAsAny, 1)
// defer fmt.Println("countParallelAsAny", countParallelAsAny)
switch
m
:=
msg
.
(
type
)
{
case
*
base
.
EthTx
:
...
...
@@ -142,6 +149,9 @@ func (*RingServer) SendTxAsBytes(ctx context.Context, in *base.TransactionBytes)
return
nil
,
err
}
// atomic.AddInt64(&countParallelAsBytes, 1)
// defer fmt.Printf("countParallelAsBytes: %d\n", countParallelAsBytes)
return
&
ring
.
SendRawTransactionResponse
{
TxHash
:
ethTx
.
Hash
()
.
Bytes
()},
nil
}
...
...
@@ -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 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
//BenchmarkAny
...
...
@@ -210,15 +235,10 @@ var onceHash sync.Once
func
BenchmarkEthTx
(
b
*
testing
.
B
)
{
// count++
// defer fmt.Println("defer countParallel", countParallel)
// defer fmt.Println("defer count", count)
// defer fmt.Println("defer b.N", b.N)
b
.
Logf
(
"b.N: %d
\n
"
,
b
.
N
)
onceFunc
:=
func
()
{
//fmt.Println("once b.N", b.N)
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
publicKey
:=
local
.
Public
()
publicKeyECDSA
,
_
:=
publicKey
.
(
*
ecdsa
.
PublicKey
)
...
...
@@ -230,15 +250,11 @@ func BenchmarkEthTx(b *testing.B) {
once
.
Do
(
onceFunc
)
b
.
Re
portAllocs
()
b
.
Re
setTimer
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
//countParallel++
for
pb
.
Next
()
{
//for i := 0; i < b.N; i++ { //串行
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9006"
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
b
.
Fatal
(
err
)
...
...
@@ -284,17 +300,15 @@ func BenchmarkEthTx(b *testing.B) {
onceHash
.
Do
(
func
()
{
b
.
Logf
(
"response: %x local: %x
\n
"
,
res
.
TxHash
,
tx
.
Hash
()
.
Bytes
())
})
//fmt.Printf("%x \n", res.TxHash)
}
})
//}
}
func
BenchmarkStdTx
(
b
*
testing
.
B
)
{
b
.
Logf
(
"b.N: %d
\n
"
,
b
.
N
)
onceFunc
:=
func
()
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
publicKey
:=
local
.
Public
()
...
...
@@ -307,7 +321,7 @@ func BenchmarkStdTx(b *testing.B) {
once
.
Do
(
onceFunc
)
b
.
Re
portAllocs
()
b
.
Re
setTimer
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
...
...
@@ -377,7 +391,7 @@ func BenchmarkAnyTx(b *testing.B) {
once
.
Do
(
onceFunc
)
b
.
Re
portAllocs
()
b
.
Re
setTimer
()
// The loop body is executed b.N times total across all goroutines.
...
...
@@ -452,7 +466,7 @@ func BenchmarkBytesEth(b *testing.B) {
once
.
Do
(
onceFunc
)
b
.
Re
portAllocs
()
b
.
Re
setTimer
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
...
...
@@ -539,14 +553,6 @@ func TestAnyTx(t *testing.T) {
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
()))
if
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
@@ -634,6 +640,13 @@ func TestAnyTx(t *testing.T) {
_
=
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"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment