diff options
author | Rob Pike <r@golang.org> | 2011-04-26 16:16:51 -0700 |
---|---|---|
committer | Rob Pike <r@golang.org> | 2011-04-26 16:16:51 -0700 |
commit | a2014f104c47225052acd75d8b3bd265c7175235 (patch) | |
tree | 6c0da18523afedfcbacef45b9125b55ca3f99c49 | |
parent | a0a10d1988b5fe242d768402b406342fe47ad5b2 (diff) | |
download | go-a2014f104c47225052acd75d8b3bd265c7175235.tar.gz go-a2014f104c47225052acd75d8b3bd265c7175235.zip |
rpc: run benchmarks over HTTP as well as direct network connections.
R=bradfitzgo
CC=golang-dev
https://golang.org/cl/4442085
-rw-r--r-- | src/pkg/rpc/server_test.go | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/src/pkg/rpc/server_test.go b/src/pkg/rpc/server_test.go index eb7b673d66..cfff0c9ad5 100644 --- a/src/pkg/rpc/server_test.go +++ b/src/pkg/rpc/server_test.go @@ -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) +} |