Browse Source

Adds benchmarks

Manu Mtz-Almeida 10 years ago
parent
commit
092a804d3e
1 changed files with 51 additions and 0 deletions
  1. 51 0
      sse_test.go

+ 51 - 0
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("Content-Type"), "text/event-stream")
 	assert.Equal(t, w.Header().Get("Cache-Control"), "no-cache")
 	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!!!",
+		})
+	}
+}