mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rpc: add benchmark notify
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
2f66d7c47c
commit
6502413f26
1 changed files with 35 additions and 0 deletions
|
|
@ -17,12 +17,17 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewID(t *testing.T) {
|
func TestNewID(t *testing.T) {
|
||||||
|
|
@ -218,3 +223,33 @@ func readAndValidateMessage(in *json.Decoder) (*subConfirmation, *subscriptionRe
|
||||||
return nil, nil, fmt.Errorf("unrecognized message: %v", msg)
|
return nil, nil, fmt.Errorf("unrecognized message: %v", msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mockConn struct{}
|
||||||
|
|
||||||
|
// writeJSON writes a message to the connection.
|
||||||
|
func (c *mockConn) writeJSON(ctx context.Context, msg interface{}, isError bool) error { return nil }
|
||||||
|
|
||||||
|
// Closed returns a channel which is closed when the connection is closed.
|
||||||
|
func (c *mockConn) closed() <-chan interface{} { return nil }
|
||||||
|
|
||||||
|
// RemoteAddr returns the peer address of the connection.
|
||||||
|
func (c *mockConn) remoteAddr() string { return "" }
|
||||||
|
|
||||||
|
// BenchmarkNotify benchmarks the performance of notifying a subscription.
|
||||||
|
func BenchmarkNotify(b *testing.B) {
|
||||||
|
id := ID("test")
|
||||||
|
notifier := &Notifier{
|
||||||
|
h: &handler{conn: &mockConn{}},
|
||||||
|
sub: &Subscription{ID: id},
|
||||||
|
activated: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
msg := &types.Header{
|
||||||
|
ParentHash: common.HexToHash("0x01"),
|
||||||
|
Number: big.NewInt(100),
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
notifier.Notify(id, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue