net/http: add Hihack benchmark

Notably, to show allocs. Currently: 11766 B/op, 21 allocs/op,
at least one alloc of which is in the benchmark loop itself.

R=golang-dev, jnewlin
CC=golang-dev
https://golang.org/cl/40370057
This commit is contained in:
Brad Fitzpatrick 2013-12-19 13:24:42 -08:00
parent e6b023473e
commit cbf6ff3b90
1 changed files with 25 additions and 0 deletions

View File

@ -2390,3 +2390,28 @@ Host: golang.org
b.Errorf("b.N=%d but handled %d", b.N, handled)
}
}
func BenchmarkServerHijack(b *testing.B) {
b.ReportAllocs()
req := reqBytes(`GET / HTTP/1.1
Host: golang.org
`)
h := HandlerFunc(func(w ResponseWriter, r *Request) {
conn, _, err := w.(Hijacker).Hijack()
if err != nil {
panic(err)
}
conn.Close()
})
conn := &rwTestConn{
Writer: ioutil.Discard,
closec: make(chan bool, 1),
}
ln := &oneConnListener{conn: conn}
for i := 0; i < b.N; i++ {
conn.Reader = bytes.NewReader(req)
ln.conn = conn
go Serve(ln, h)
<-conn.closec
}
}