mirror of
https://github.com/golang/go
synced 2024-11-22 02:04:40 -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:
parent
f7a266a5aa
commit
399a311e64
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user