8b374d7f by astaxie

beego: add benchmark

1 parent fa323414
...@@ -10,7 +10,6 @@ import ( ...@@ -10,7 +10,6 @@ import (
10 "net/http" 10 "net/http"
11 "net/http/httptest" 11 "net/http/httptest"
12 "testing" 12 "testing"
13
14 "github.com/astaxie/beego/context" 13 "github.com/astaxie/beego/context"
15 ) 14 )
16 15
...@@ -273,3 +272,46 @@ func TestRouterHandler(t *testing.T) { ...@@ -273,3 +272,46 @@ func TestRouterHandler(t *testing.T) {
273 t.Errorf("TestRouterHandler can't run") 272 t.Errorf("TestRouterHandler can't run")
274 } 273 }
275 } 274 }
275
276 //
277 // Benchmarks NewApp:
278 //
279
280 func beegoFilterFunc(ctx *context.Context) {
281 ctx.WriteString("hello")
282 }
283
284 type AdminController struct {
285 Controller
286 }
287
288 func (a *AdminController) Get() {
289 a.Ctx.WriteString("hello")
290 }
291
292 func BenchmarkFunc(b *testing.B) {
293 mux := NewControllerRegistor()
294 mux.Get("/action", beegoFilterFunc)
295 rw, r := testRequest("GET", "/action")
296 b.ResetTimer()
297 for i := 0; i < b.N; i++ {
298 mux.ServeHTTP(rw, r)
299 }
300 }
301
302 func BenchmarkController(b *testing.B) {
303 mux := NewControllerRegistor()
304 mux.Add("/action", &AdminController{})
305 rw, r := testRequest("GET", "/action")
306 b.ResetTimer()
307 for i := 0; i < b.N; i++ {
308 mux.ServeHTTP(rw, r)
309 }
310 }
311
312 func testRequest(method, path string) (*httptest.ResponseRecorder, *http.Request) {
313 request, _ := http.NewRequest(method, path, nil)
314 recorder := httptest.NewRecorder()
315
316 return recorder, request
317 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!