1
0
mirror of https://github.com/golang/go synced 2024-11-25 05:57:57 -07:00

http: client+server benchmark

baseline runs: (6g, gopher.mtv)

http_test.BenchmarkClientServer  5000  412588 ns/op
http_test.BenchmarkClientServer  5000  403346 ns/op
http_test.BenchmarkClientServer  5000  413936 ns/op
http_test.BenchmarkClientServer  5000  410287 ns/op
http_test.BenchmarkClientServer  5000  388037 ns/op
http_test.BenchmarkClientServer  5000  405545 ns/op
http_test.BenchmarkClientServer  5000  405179 ns/op
http_test.BenchmarkClientServer  5000  413827 ns/op
http_test.BenchmarkClientServer  5000  392723 ns/op

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/4515155
This commit is contained in:
Brad Fitzpatrick 2011-05-27 16:43:02 -07:00
parent f7a266a5aa
commit 399a311e64

View File

@ -754,3 +754,29 @@ func TestZeroLengthPostAndResponse(t *testing.T) {
}
}
}
func BenchmarkClientServer(b *testing.B) {
b.StopTimer()
ts := httptest.NewServer(HandlerFunc(func(rw ResponseWriter, r *Request) {
fmt.Fprintf(rw, "Hello world.\n")
}))
defer ts.Close()
b.StartTimer()
for i := 0; i < b.N; i++ {
res, err := Get(ts.URL)
if err != nil {
panic("Get: " + err.String())
}
all, err := ioutil.ReadAll(res.Body)
if err != nil {
panic("ReadAll: " + err.String())
}
body := string(all)
if body != "Hello world.\n" {
panic("Got body: " + body)
}
}
b.StopTimer()
}