Skip to content

Instantly share code, notes, and snippets.

@FZambia
Created March 19, 2019 14:56
Show Gist options
  • Select an option

  • Save FZambia/0da661b055cb6d12c9ddf0566fc60c67 to your computer and use it in GitHub Desktop.

Select an option

Save FZambia/0da661b055cb6d12c9ddf0566fc60c67 to your computer and use it in GitHub Desktop.
Gorilla Websocket Upgrade Benchmark
func BenchmarkUpgrade(b *testing.B) {
br := bufio.NewReaderSize(strings.NewReader(""), 4096)
bw := bufio.NewWriterSize(&bytes.Buffer{}, 4096)
upgrader := Upgrader{
ReadBufferSize: 0,
WriteBufferSize: 0,
}
resp := &reuseTestResponseWriter{
brw: bufio.NewReadWriter(br, bw),
}
req := &http.Request{
Method: "GET",
Header: http.Header{
"Upgrade": []string{"websocket"},
"Connection": []string{"upgrade"},
"Sec-Websocket-Key": []string{"dGhlIHNhbXBsZSBub25jZQ=="},
"Sec-Websocket-Version": []string{"13"},
},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
c, err := upgrader.Upgrade(resp, req, nil)
if err != nil {
panic(err)
}
if c == nil {
panic("conn is nil")
}
}
b.ReportAllocs()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment