2
0

Adds benchmarks

This commit is contained in:
Manu Mtz-Almeida
2015-05-30 11:21:18 +02:00
parent b7eeebd898
commit 092a804d3e
+51
View File
@@ -163,3 +163,54 @@ func TestRenderSSE(t *testing.T) {
assert.Equal(t, w.Header().Get("Content-Type"), "text/event-stream")
assert.Equal(t, w.Header().Get("Cache-Control"), "no-cache")
}
func BenchmarkResponseWriter(b *testing.B) {
w := httptest.NewRecorder()
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
(Event{
Event: "new_message",
Data: "hi! how are you? I am fine. this is a long stupid message!!!",
}).Write(w)
}
}
func BenchmarkFullSSE(b *testing.B) {
buf := new(bytes.Buffer)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Encode(buf, Event{
Event: "new_message",
Id: "13435",
Retry: 10,
Data: "hi! how are you? I am fine. this is a long stupid message!!!",
})
}
}
func BenchmarkNoRetrySSE(b *testing.B) {
buf := new(bytes.Buffer)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Encode(buf, Event{
Event: "new_message",
Id: "13435",
Data: "hi! how are you? I am fine. this is a long stupid message!!!",
})
}
}
func BenchmarkSimpleSSE(b *testing.B) {
buf := new(bytes.Buffer)
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
Encode(buf, Event{
Event: "new_message",
Data: "hi! how are you? I am fine. this is a long stupid message!!!",
})
}
}