More benchmarks
This commit is contained in:
parent
43bcac2031
commit
aa9078bc73
@ -2,7 +2,7 @@ package gin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@ -63,13 +63,28 @@ func BenchmarkOneRouteJSON(B *testing.B) {
|
|||||||
"status": "ok",
|
"status": "ok",
|
||||||
}
|
}
|
||||||
router.GET("/json", func(c *Context) {
|
router.GET("/json", func(c *Context) {
|
||||||
//c.JSON(200, data)
|
c.JSON(200, data)
|
||||||
c.Writer.WriteHeader(200)
|
|
||||||
json.NewEncoder(c.Writer).Encode(data)
|
|
||||||
})
|
})
|
||||||
runRequest(B, router, "GET", "/json")
|
runRequest(B, router, "GET", "/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var htmlContentType = []string{"text/html; charset=utf-8"}
|
||||||
|
|
||||||
|
func BenchmarkOneRouteHTML(B *testing.B) {
|
||||||
|
router := New()
|
||||||
|
t := template.Must(template.New("index").Parse(`
|
||||||
|
<html><body><h1>{{.}}</h1></body></html>`))
|
||||||
|
router.SetHTMLTemplate(t)
|
||||||
|
|
||||||
|
router.GET("/html", func(c *Context) {
|
||||||
|
//c.Writer.Header()["Content-Type"] = htmlContentType
|
||||||
|
//t.ExecuteTemplate(c.Writer, "index", "hola")
|
||||||
|
|
||||||
|
c.HTML(200, "index", "hola")
|
||||||
|
})
|
||||||
|
runRequest(B, router, "GET", "/html")
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkOneRouteString(B *testing.B) {
|
func BenchmarkOneRouteString(B *testing.B) {
|
||||||
router := New()
|
router := New()
|
||||||
router.GET("/text", func(c *Context) {
|
router.GET("/text", func(c *Context) {
|
||||||
|
@ -127,11 +127,11 @@ func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) {
|
|||||||
panic("URL parameters can not be used when serving a static folder")
|
panic("URL parameters can not be used when serving a static folder")
|
||||||
}
|
}
|
||||||
handler := group.createStaticHandler(relativePath, fs)
|
handler := group.createStaticHandler(relativePath, fs)
|
||||||
relativePath = path.Join(relativePath, "/*filepath")
|
urlPattern := path.Join(relativePath, "/*filepath")
|
||||||
|
|
||||||
// Register GET and HEAD handlers
|
// Register GET and HEAD handlers
|
||||||
group.GET(relativePath, handler)
|
group.GET(urlPattern, handler)
|
||||||
group.HEAD(relativePath, handler)
|
group.HEAD(urlPattern, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileSystem) HandlerFunc {
|
||||||
|
Loading…
Reference in New Issue
Block a user