-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench_test.go
66 lines (59 loc) · 1.41 KB
/
bench_test.go
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
package main
import (
"fmt"
"github.com/upamanyus/urpc/rpc"
"testing"
"time"
"sync"
)
func TestRPC(t *testing.T) {
fmt.Println("==Basic urpc test")
client := rpc.MakeRPCClient("localhost:12345")
var reply []byte
args := make([]byte, 0)
reply = make([]byte, 0)
client.Call(1, args, &reply)
fmt.Printf("%s\n", string(reply))
}
func TestBenchRPC(t *testing.T) {
fmt.Println("==Benchmarking urpc")
client := rpc.MakeRPCClient("localhost:12345")
start := time.Now()
N := 200000
var reply []byte
args := make([]byte, 0)
for n := 0; n < N; n++ {
reply = make([]byte, 0)
client.Call(1, args, &reply)
}
d := time.Since(start)
fmt.Printf("%v us/op\n", d.Microseconds()/int64(N))
fmt.Printf("%v ops/sec\n", float64(N) / d.Seconds())
}
func TestBenchConcurrentRPC(t *testing.T) {
fmt.Println("==Benchmarking urpc")
numClients := 40
clients := make([]*rpc.RPCClient, numClients)
for i := 0; i < numClients; i++ {
clients[i] = rpc.MakeRPCClient("localhost:12345")
}
var wg sync.WaitGroup
N := 50000
start := time.Now()
args := make([]byte, 128)
for i := 0; i < numClients; i++ {
wg.Add(1)
go func(i int) {
var reply []byte
for n := 0; n < N; n++ {
reply = make([]byte, 0)
clients[i].Call(1, args, &reply)
}
wg.Done()
}(i)
}
wg.Wait()
d := time.Since(start)
fmt.Printf("%v us/op\n", d.Microseconds()/int64(N))
fmt.Printf("%v ops/sec\n", float64(N * numClients) / d.Seconds())
}