Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package jrpc
import (
"testing"
"golang.org/x/sync/errgroup"
)
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.
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"},
}
b.StartTimer()
for n := 0; n < b.N; n++ {
eg := &errgroup.Group{}
for i := 0; i < 1000; i++ {
eg.Go(func() error {
return client.Call(nil, "test_echoAny", []any{1, 2, 3, 4, 56, 6, wantBack, wantBack, wantBack})
})
}
eg.Wait()
}
}
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()
for n := 0; n < b.N; n++ {
eg := &errgroup.Group{}
for i := 0; i < 1000; i++ {
eg.Go(func() error {
return client.Call(nil, "test_echoAny", 0)
})
}
eg.Wait()
}
}
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.
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"},
}
payload := []any{1, 2, 3, 4, 56, 6, wantBack, wantBack, wantBack}
b.StartTimer()
for n := 0; n < b.N; n++ {
eg := &errgroup.Group{}
for i := 0; i < 1000; i++ {
eg.Go(func() error {
})
}
eg.Wait()
}
}
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()
for n := 0; n < b.N; n++ {
eg := &errgroup.Group{}
for i := 0; i < 1000; i++ {
eg.Go(func() error {
return client.Call(nil, "test_echoAny", 0)
})
}
eg.Wait()
}
}