]> Cypherpunks repositories - gostls13.git/commitdiff
rpc: run benchmarks over HTTP as well as direct network connections.
authorRob Pike <r@golang.org>
Tue, 26 Apr 2011 23:16:51 +0000 (16:16 -0700)
committerRob Pike <r@golang.org>
Tue, 26 Apr 2011 23:16:51 +0000 (16:16 -0700)
R=bradfitzgo
CC=golang-dev
https://golang.org/cl/4442085

src/pkg/rpc/server_test.go

index eb7b673d661de5be59de8c1dee74ab72270fd9a5..cfff0c9ad50cc96af2664e149666b3d88458e3fe 100644 (file)
@@ -344,18 +344,26 @@ func testSendDeadlock(client *Client) {
        client.Call("Arith.Add", args, reply)
 }
 
-func TestCountMallocs(t *testing.T) {
+func dialDirect() (*Client, os.Error) {
+       return Dial("tcp", serverAddr)
+}
+
+func dialHTTP() (*Client, os.Error) {
+       return DialHTTP("tcp", httpServerAddr)
+}
+
+func countMallocs(dial func() (*Client, os.Error), t *testing.T) uint64 {
        once.Do(startServer)
-       client, err := Dial("tcp", serverAddr)
+       client, err := dial()
        if err != nil {
-               t.Error("error dialing", err)
+               t.Fatal("error dialing", err)
        }
        args := &Args{7, 8}
        reply := new(Reply)
        mallocs := 0 - runtime.MemStats.Mallocs
        const count = 100
        for i := 0; i < count; i++ {
-               err = client.Call("Arith.Add", args, reply)
+               err := client.Call("Arith.Add", args, reply)
                if err != nil {
                        t.Errorf("Add: expected no error but got string %q", err.String())
                }
@@ -364,13 +372,21 @@ func TestCountMallocs(t *testing.T) {
                }
        }
        mallocs += runtime.MemStats.Mallocs
-       fmt.Printf("mallocs per rpc round trip: %d\n", mallocs/count)
+       return mallocs / count
 }
 
-func BenchmarkEndToEnd(b *testing.B) {
+func TestCountMallocs(t *testing.T) {
+       fmt.Printf("mallocs per rpc round trip: %d\n", countMallocs(dialDirect, t))
+}
+
+func TestCountMallocsOverHTTP(t *testing.T) {
+       fmt.Printf("mallocs per HTTP rpc round trip: %d\n", countMallocs(dialHTTP, t))
+}
+
+func benchmarkEndToEnd(dial func() (*Client, os.Error), b *testing.B) {
        b.StopTimer()
        once.Do(startServer)
-       client, err := Dial("tcp", serverAddr)
+       client, err := dial()
        if err != nil {
                fmt.Println("error dialing", err)
                return
@@ -392,3 +408,11 @@ func BenchmarkEndToEnd(b *testing.B) {
                }
        }
 }
+
+func BenchmarkEndToEnd(b *testing.B) {
+       benchmarkEndToEnd(dialDirect, b)
+}
+
+func BenchmarkEndToEndHTTP(b *testing.B) {
+       benchmarkEndToEnd(dialHTTP, b)
+}