From: Brad Fitzpatrick Date: Thu, 19 Dec 2013 21:24:42 +0000 (-0800) Subject: net/http: add Hihack benchmark X-Git-Tag: go1.3beta1~1136 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cbf6ff3b90f5b70e9e7f6aafc1744efbb4761377;p=gostls13.git 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 --- diff --git a/src/pkg/net/http/serve_test.go b/src/pkg/net/http/serve_test.go index 955112bc2b..af33b5e10b 100644 --- a/src/pkg/net/http/serve_test.go +++ b/src/pkg/net/http/serve_test.go @@ -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 + } +}