Add basic benchmakrs

This commit is contained in:
Leonid Bugaev
2013-11-02 16:53:59 +01:00
parent fa9c9c3387
commit f8a8444b27
2 changed files with 74 additions and 10 deletions
+26
View File
@@ -71,3 +71,29 @@ func TestEmitterRoundRobin(t *testing.T) {
Settings.splitOutput = false
}
func BenchmarkEmitter(b *testing.B) {
wg := new(sync.WaitGroup)
quit := make(chan int)
input := NewTestInput()
output := NewTestOutput(func(data []byte) {
wg.Done()
})
Plugins.Inputs = []io.Reader{input}
Plugins.Outputs = []io.Writer{output}
go Start(quit)
b.ResetTimer()
for i := 0; i < b.N; i++ {
wg.Add(1)
input.EmitGET()
}
wg.Wait()
close(quit)
}
+48 -10
View File
@@ -1,30 +1,35 @@
package gor
import (
"fmt"
"io"
"net"
"net/http"
"sync"
"testing"
)
func startHTTP(cb func(*http.Request)) net.Listener {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cb(r)
})
listener, _ := net.Listen("tcp", ":0")
go http.Serve(listener, handler)
return listener
}
func TestHTTPOutput(t *testing.T) {
startHTTP := func(addr string, cb func(*http.Request)) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cb(r)
})
go http.ListenAndServe(addr, handler)
}
wg := new(sync.WaitGroup)
quit := make(chan int)
input := NewTestInput()
headers := HTTPHeaders{HTTPHeader{"User-Agent", "Gor"}}
output := NewHTTPOutput("127.0.0.1:50003", headers, "")
startHTTP("127.0.0.1:50003", func(req *http.Request) {
listener := startHTTP(func(req *http.Request) {
if req.Header.Get("User-Agent") != "Gor" {
t.Error("Wrong header")
}
@@ -32,6 +37,8 @@ func TestHTTPOutput(t *testing.T) {
wg.Done()
})
output := NewHTTPOutput(listener.Addr().String(), headers, "")
Plugins.Inputs = []io.Reader{input}
Plugins.Outputs = []io.Writer{output}
@@ -47,3 +54,34 @@ func TestHTTPOutput(t *testing.T) {
close(quit)
}
func BenchmarkHTTPOutput(b *testing.B) {
wg := new(sync.WaitGroup)
quit := make(chan int)
input := NewTestInput()
headers := HTTPHeaders{HTTPHeader{"User-Agent", "Gor"}}
listener := startHTTP(func(req *http.Request) {
go wg.Done()
})
output := NewHTTPOutput(listener.Addr().String(), headers, "")
Plugins.Inputs = []io.Reader{input}
Plugins.Outputs = []io.Writer{output}
go Start(quit)
fmt.Println(b)
for i := 0; i < b.N; i++ {
wg.Add(1)
input.EmitPOST()
}
wg.Wait()
close(quit)
}