aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/httputil/reverseproxy_test.go
diff options
context:
space:
mode:
authorBlake Mizerany <blake.mizerany@gmail.com>2017-01-23 11:03:03 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2017-02-01 21:43:05 +0000
commitb48c419c4109a1c0e1e7a60a7a28659f6a92e827 (patch)
tree89952b6b949bc22b49d355c7323ec025102fab9e /src/net/http/httputil/reverseproxy_test.go
parent435450bf3c6efcc65111e96a42fc1c8acd3081e3 (diff)
downloadgo-b48c419c4109a1c0e1e7a60a7a28659f6a92e827.tar.gz
go-b48c419c4109a1c0e1e7a60a7a28659f6a92e827.zip
net/http/httputil: eliminate duplicate alloc/copy in ReverseProxy
This commit elimates the request allocation and shallow copy duplication already done by req.WithContext. name old time/op new time/op delta ServeHTTP-4 216µs ±36% 212µs ±15% ~ (p=0.853 n=10+10) name old alloc/op new alloc/op delta ServeHTTP-4 917kB ±36% 1137kB ± 0% ~ (p=0.352 n=10+10) name old allocs/op new allocs/op delta ServeHTTP-4 5.00 ± 0% 4.00 ± 0% -20.00% (p=0.000 n=10+10) Change-Id: I514a59c30b037c7a65c355b06fd82c2d6ff17bb0 Reviewed-on: https://go-review.googlesource.com/35569 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/httputil/reverseproxy_test.go')
-rw-r--r--src/net/http/httputil/reverseproxy_test.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/net/http/httputil/reverseproxy_test.go b/src/net/http/httputil/reverseproxy_test.go
index 20c4e16bcb..9153508ef4 100644
--- a/src/net/http/httputil/reverseproxy_test.go
+++ b/src/net/http/httputil/reverseproxy_test.go
@@ -664,3 +664,30 @@ func TestReverseProxy_CopyBuffer(t *testing.T) {
}
}
}
+
+type staticTransport struct {
+ res *http.Response
+}
+
+func (t *staticTransport) RoundTrip(r *http.Request) (*http.Response, error) {
+ return t.res, nil
+}
+
+func BenchmarkServeHTTP(b *testing.B) {
+ res := &http.Response{
+ StatusCode: 200,
+ Body: ioutil.NopCloser(strings.NewReader("")),
+ }
+ proxy := &ReverseProxy{
+ Director: func(*http.Request) {},
+ Transport: &staticTransport{res},
+ }
+
+ w := httptest.NewRecorder()
+ r := httptest.NewRequest("GET", "/", nil)
+
+ b.ReportAllocs()
+ for i := 0; i < b.N; i++ {
+ proxy.ServeHTTP(w, r)
+ }
+}