From 092a804d3e692396158406848f53bb0796792b0f Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Sat, 30 May 2015 11:21:18 +0200 Subject: [PATCH] Adds benchmarks --- sse_test.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/sse_test.go b/sse_test.go index 55b6dcb..13cdf46 100644 --- a/sse_test.go +++ b/sse_test.go @@ -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!!!", + }) + } +}