(b *testing.B)
| 94 | } |
| 95 | |
| 96 | func BenchmarkHttpWriteUpgradeRequest(b *testing.B) { |
| 97 | for _, test := range []struct { |
| 98 | url *url.URL |
| 99 | protocols []string |
| 100 | extensions []httphead.Option |
| 101 | headers HandshakeHeaderFunc |
| 102 | host string |
| 103 | }{ |
| 104 | { |
| 105 | url: makeURL("ws://example.org"), |
| 106 | }, |
| 107 | { |
| 108 | url: makeURL("ws://example.org"), |
| 109 | host: "test-host", |
| 110 | }, |
| 111 | } { |
| 112 | bw := bufio.NewWriter(ioutil.Discard) |
| 113 | nonce := make([]byte, nonceSize) |
| 114 | initNonce(nonce) |
| 115 | |
| 116 | var headers HandshakeHeader |
| 117 | if test.headers != nil { |
| 118 | headers = test.headers |
| 119 | } |
| 120 | |
| 121 | b.ResetTimer() |
| 122 | b.Run("", func(b *testing.B) { |
| 123 | for i := 0; i < b.N; i++ { |
| 124 | httpWriteUpgradeRequest(bw, |
| 125 | test.url, |
| 126 | nonce, |
| 127 | test.protocols, |
| 128 | test.extensions, |
| 129 | headers, |
| 130 | test.host, |
| 131 | ) |
| 132 | } |
| 133 | }) |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | func makeURL(s string) *url.URL { |
| 138 | ret, err := url.Parse(s) |
nothing calls this directly
no test coverage detected
searching dependent graphs…