good morning!!!!

Skip to content
Snippets Groups Projects
Commit 60bc0955 authored by a's avatar a
Browse files

add benchmark

parent 4751dffd
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ package jrpc
import (
"context"
"encoding/json"
"fmt"
"math/rand"
"net"
......@@ -334,6 +335,86 @@ func TestClientHTTP(t *testing.T) {
}
}
func BenchmarkClientHTTPEcho(b *testing.B) {
server := newTestServer()
defer server.Stop()
client, hs := httpTestClient(server, "http", nil)
defer hs.Close()
defer client.Close()
// Launch concurrent requests.
b.StartTimer()
wantBack := map[string]any{
"one": map[string]any{"two": "three"},
"e": map[string]any{"two": "three"},
"oe": map[string]any{"two": "three"},
"on": map[string]any{"two": "three"},
}
var res json.RawMessage
for n := 0; n < b.N; n++ {
for i := 0; i < 100; i++ {
err := client.Call(&res, "test_echoAny", []any{1, 2, 3, 4, 56, 6, wantBack, wantBack, wantBack})
if err != nil {
panic(err)
}
}
}
}
func BenchmarkClientHTTPEchoEmpty(b *testing.B) {
server := newTestServer()
defer server.Stop()
client, hs := httpTestClient(server, "http", nil)
defer hs.Close()
defer client.Close()
// Launch concurrent requests.
b.StartTimer()
var res json.RawMessage
for n := 0; n < b.N; n++ {
for i := 0; i < 100; i++ {
client.Call(&res, "test_echoAny", 0)
}
}
}
func BenchmarkClientWebsocketEcho(b *testing.B) {
server := newTestServer()
defer server.Stop()
client, hs := httpTestClient(server, "ws", nil)
defer hs.Close()
defer client.Close()
// Launch concurrent requests.
b.StartTimer()
wantBack := map[string]any{
"one": map[string]any{"two": "three"},
"e": map[string]any{"two": "three"},
"oe": map[string]any{"two": "three"},
"on": map[string]any{"two": "three"},
}
var res json.RawMessage
for n := 0; n < b.N; n++ {
for i := 0; i < 100; i++ {
client.Call(&res, "test_echoAny", []any{1, 2, 3, 4, 56, 6, wantBack, wantBack, wantBack})
}
}
}
func BenchmarkClientWebsocketEchoEmpty(b *testing.B) {
server := newTestServer()
defer server.Stop()
client, hs := httpTestClient(server, "ws", nil)
defer hs.Close()
defer client.Close()
// Launch concurrent requests.
b.StartTimer()
var res json.RawMessage
for n := 0; n < b.N; n++ {
for i := 0; i < 100; i++ {
client.Call(&res, "test_echoAny", 0)
}
}
}
func TestClientReconnect(t *testing.T) {
startServer := func(addr string) (*Server, net.Listener) {
srv := newTestServer()
......
[1,2,3,4,56,6,{"e":{"two":"three"},"oe":{"two":"three"},"on":{"two":"three"},"one":{"two":"three"}},{"e":{"two":"three"},"oe":{"two":"three"},"on":{"two":"three"},"one":{"two":"three"}},{"e":{"two":"three"},"oe":{"two":"three"},"on":{"two":"three"},"one":{"two":"three"}}]
\ No newline at end of file
......@@ -54,6 +54,10 @@ func (testError) ErrorData() any { return "testError data" }
func (s *testService) NoArgsRets() {}
func (s *testService) EchoAny(n any) any {
return n
}
func (s *testService) Echo(str string, i int, args *echoArgs) echoResult {
return echoResult{str, i, args}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment