Skip to content

Commit 0e56555

Browse files
committed
Add benchmarks for processing GET and POST requests
1 parent 644d4bf commit 0e56555

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

web_test.go

+34
Original file line numberDiff line numberDiff line change
@@ -534,3 +534,37 @@ func BuildBasicAuthCredentials(user string, pass string) string {
534534
s := user + ":" + pass
535535
return "Basic "+base64.StdEncoding.EncodeToString([]byte(s))
536536
}
537+
538+
func BenchmarkProcessGet(b *testing.B) {
539+
s := NewServer()
540+
s.SetLogger(log.New(ioutil.Discard, "", 0))
541+
s.Get("/echo/(.*)", func(s string) string {
542+
return s
543+
})
544+
req := buildTestRequest("GET", "/echo/hi", "", nil, nil)
545+
var buf bytes.Buffer
546+
iob := ioBuffer{input: nil, output: &buf}
547+
c := scgiConn{wroteHeaders: false, req: req, headers: make(map[string][]string), fd: &iob}
548+
b.ReportAllocs()
549+
b.ResetTimer()
550+
for i := 0; i < b.N; i++ {
551+
s.Process(&c, req)
552+
}
553+
}
554+
555+
func BenchmarkProcessPost(b *testing.B) {
556+
s := NewServer()
557+
s.SetLogger(log.New(ioutil.Discard, "", 0))
558+
s.Post("/echo/(.*)", func(s string) string {
559+
return s
560+
})
561+
req := buildTestRequest("POST", "/echo/hi", "", nil, nil)
562+
var buf bytes.Buffer
563+
iob := ioBuffer{input: nil, output: &buf}
564+
c := scgiConn{wroteHeaders: false, req: req, headers: make(map[string][]string), fd: &iob}
565+
b.ReportAllocs()
566+
b.ResetTimer()
567+
for i := 0; i < b.N; i++ {
568+
s.Process(&c, req)
569+
}
570+
}

0 commit comments

Comments
 (0)