mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:50:54 +00:00
beego: add benchmark
This commit is contained in:
parent
fa3234147a
commit
8b374d7f90
@ -10,7 +10,6 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/astaxie/beego/context"
|
||||
)
|
||||
|
||||
@ -273,3 +272,46 @@ func TestRouterHandler(t *testing.T) {
|
||||
t.Errorf("TestRouterHandler can't run")
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Benchmarks NewApp:
|
||||
//
|
||||
|
||||
func beegoFilterFunc(ctx *context.Context) {
|
||||
ctx.WriteString("hello")
|
||||
}
|
||||
|
||||
type AdminController struct {
|
||||
Controller
|
||||
}
|
||||
|
||||
func (a *AdminController) Get() {
|
||||
a.Ctx.WriteString("hello")
|
||||
}
|
||||
|
||||
func BenchmarkFunc(b *testing.B) {
|
||||
mux := NewControllerRegistor()
|
||||
mux.Get("/action", beegoFilterFunc)
|
||||
rw, r := testRequest("GET", "/action")
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
mux.ServeHTTP(rw, r)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkController(b *testing.B) {
|
||||
mux := NewControllerRegistor()
|
||||
mux.Add("/action", &AdminController{})
|
||||
rw, r := testRequest("GET", "/action")
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
mux.ServeHTTP(rw, r)
|
||||
}
|
||||
}
|
||||
|
||||
func testRequest(method, path string) (*httptest.ResponseRecorder, *http.Request) {
|
||||
request, _ := http.NewRequest(method, path, nil)
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
return recorder, request
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user