]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: add Hihack benchmark
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 19 Dec 2013 21:24:42 +0000 (13:24 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 19 Dec 2013 21:24:42 +0000 (13:24 -0800)
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

src/pkg/net/http/serve_test.go

index 955112bc2bff0cce0ca56132c78c546c0dc26236..af33b5e10b7e07001686e7e169ae7574ee538ce9 100644 (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
+       }
+}