Skip to content

Add a new router benchmarks add #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ func BenchmarkRivet_Param(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkSee_Param(b *testing.B) {
router := loadSeeSingle("GET", "/user/:name", seeHandle)

r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkTango_Param(b *testing.B) {
router := loadTangoSingle("GET", "/user/:name", tangoHandler)

Expand Down Expand Up @@ -487,6 +493,12 @@ func BenchmarkRivet_Param5(b *testing.B) {
r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkSee_Param5(b *testing.B) {
router := loadSeeSingle("GET", fiveColon, seeHandle)

r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkTango_Param5(b *testing.B) {
router := loadTangoSingle("GET", fiveColon, tangoHandler)

Expand Down Expand Up @@ -697,6 +709,12 @@ func BenchmarkRivet_Param20(b *testing.B) {
r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkSee_Param20(b *testing.B) {
router := loadSeeSingle("GET", twentyColon, seeHandle)

r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkTango_Param20(b *testing.B) {
router := loadTangoSingle("GET", twentyColon, tangoHandler)

Expand Down Expand Up @@ -903,6 +921,12 @@ func BenchmarkRivet_ParamWrite(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkSee_ParamWrite(b *testing.B) {
router := loadSeeSingle("GET", "/user/:name", seeHandleWrite)

r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkTango_ParamWrite(b *testing.B) {
router := loadTangoSingle("GET", "/user/:name", tangoHandlerWrite)

Expand Down
15 changes: 15 additions & 0 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ var (
githubR2router http.Handler
githubRevel http.Handler
githubRivet http.Handler
githubSee http.Handler
githubTango http.Handler
githubTigerTonic http.Handler
githubTraffic http.Handler
Expand Down Expand Up @@ -396,6 +397,9 @@ func init() {
calcMem("Rivet", func() {
githubRivet = loadRivet(githubAPI)
})
calcMem("See", func() {
githubSee = loadSee(githubAPI)
})
calcMem("Tango", func() {
githubTango = loadTango(githubAPI)
})
Expand Down Expand Up @@ -529,6 +533,10 @@ func BenchmarkRivet_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubRivet, req)
}
func BenchmarkSee_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubSee, req)
}
func BenchmarkTango_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubTango, req)
Expand Down Expand Up @@ -665,6 +673,10 @@ func BenchmarkRivet_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubRivet, req)
}
func BenchmarkSee_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubSee, req)
}
func BenchmarkTango_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubTango, req)
Expand Down Expand Up @@ -773,6 +785,9 @@ func BenchmarkR2router_GithubAll(b *testing.B) {
func BenchmarkRivet_GithubAll(b *testing.B) {
benchRoutes(b, githubRivet, githubAPI)
}
func BenchmarkSee_GithubAll(b *testing.B) {
benchRoutes(b, githubSee, githubAPI)
}
func BenchmarkTango_GithubAll(b *testing.B) {
benchRoutes(b, githubTango, githubAPI)
}
Expand Down
19 changes: 19 additions & 0 deletions gplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
gplusR2router http.Handler
gplusRevel http.Handler
gplusRivet http.Handler
gplusSee http.Handler
gplusTango http.Handler
gplusTigerTonic http.Handler
gplusTraffic http.Handler
Expand Down Expand Up @@ -158,6 +159,9 @@ func init() {
calcMem("Rivet", func() {
gplusRivet = loadRivet(gplusAPI)
})
calcMem("See", func() {
gplusSee = loadSee(gplusAPI)
})
calcMem("Tango", func() {
gplusTango = loadTango(gplusAPI)
})
Expand Down Expand Up @@ -291,6 +295,10 @@ func BenchmarkRivet_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusRivet, req)
}
func BenchmarkSee_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusSee, req)
}
func BenchmarkTango_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusTango, req)
Expand Down Expand Up @@ -427,6 +435,10 @@ func BenchmarkRivet_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusRivet, req)
}
func BenchmarkSee_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusSee, req)
}
func BenchmarkTango_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusTango, req)
Expand Down Expand Up @@ -563,6 +575,10 @@ func BenchmarkRivet_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusRivet, req)
}
func BenchmarkSee_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusSee, req)
}
func BenchmarkTango_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusTango, req)
Expand Down Expand Up @@ -671,6 +687,9 @@ func BenchmarkR2router_GPlusAll(b *testing.B) {
func BenchmarkRivet_GPlusAll(b *testing.B) {
benchRoutes(b, gplusRivet, gplusAPI)
}
func BenchmarkSee_GPlusAll(b *testing.B) {
benchRoutes(b, gplusSee, gplusAPI)
}
func BenchmarkTango_GPlusAll(b *testing.B) {
benchRoutes(b, gplusTango, gplusAPI)
}
Expand Down
19 changes: 19 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var (
parseR2router http.Handler
parseRevel http.Handler
parseRivet http.Handler
parseSee http.Handler
parseTango http.Handler
parseTigerTonic http.Handler
parseTraffic http.Handler
Expand Down Expand Up @@ -178,6 +179,9 @@ func init() {
calcMem("Rivet", func() {
parseRivet = loadRivet(parseAPI)
})
calcMem("See", func() {
parseSee = loadSee(parseAPI)
})
calcMem("Tango", func() {
parseTango = loadTango(parseAPI)
})
Expand Down Expand Up @@ -311,6 +315,10 @@ func BenchmarkRivet_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseRivet, req)
}
func BenchmarkSee_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseSee, req)
}
func BenchmarkTango_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseTango, req)
Expand Down Expand Up @@ -447,6 +455,10 @@ func BenchmarkRivet_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseRivet, req)
}
func BenchmarkSee_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseSee, req)
}
func BenchmarkTango_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseTango, req)
Expand Down Expand Up @@ -583,6 +595,10 @@ func BenchmarkRivet_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseRivet, req)
}
func BenchmarkSee_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseSee, req)
}
func BenchmarkTango_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseTango, req)
Expand Down Expand Up @@ -691,6 +707,9 @@ func BenchmarkR2router_ParseAll(b *testing.B) {
func BenchmarkRivet_ParseAll(b *testing.B) {
benchRoutes(b, parseRivet, parseAPI)
}
func BenchmarkSee_ParseAll(b *testing.B) {
benchRoutes(b, parseSee, parseAPI)
}
func BenchmarkTango_ParseAll(b *testing.B) {
benchRoutes(b, parseTango, parseAPI)
}
Expand Down
35 changes: 35 additions & 0 deletions routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
// "github.com/revel/pathtree"
// "github.com/revel/revel"
"github.com/aerogo/aero"
"github.com/junbin-yang/see"
"github.com/typepress/rivet"
"github.com/ursiform/bear"
"github.com/vanng822/r2router"
Expand Down Expand Up @@ -1455,6 +1456,40 @@ func loadRivetSingle(method, path string, handler interface{}) http.Handler {
return router
}

// See
func seeHandle(_ *see.Context) {}

func seeHandleWrite(c *see.Context) {
io.WriteString(c.Writer, c.Param("name"))
}

func seeHandleTest(c *see.Context) {
io.WriteString(c.Writer, c.RequestURI)
}

func initSee() {
see.SetMode(see.ReleaseMode)
}

func loadSee(routes []route) http.Handler {
h := seeHandle
if loadTestHandler {
h = seeHandleTest
}

router := see.New()
for _, route := range routes {
router.Handle(route.method, route.path, h)
}
return router
}

func loadSeeSingle(method, path string, handle see.HandlerFunc) http.Handler {
router := see.New()
router.Handle(method, path, handle)
return router
}

// Tango
func tangoHandler(ctx *tango.Context) {}

Expand Down
1 change: 1 addition & 0 deletions routers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
{"Traffic", loadTraffic},
{"Vulcan", loadVulcan},
// {"Zeus", loadZeus},
{"See", loadSee},
}

// all APIs
Expand Down
7 changes: 7 additions & 0 deletions static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ var (
staticR2router http.Handler
// staticRevel http.Handler
staticRivet http.Handler
staticSee http.Handler
staticTango http.Handler
staticTigerTonic http.Handler
staticTraffic http.Handler
Expand Down Expand Up @@ -302,6 +303,9 @@ func init() {
calcMem("Rivet", func() {
staticRivet = loadRivet(staticRoutes)
})
calcMem("See", func() {
staticSee = loadSee(staticRoutes)
})
calcMem("Tango", func() {
staticTango = loadTango(staticRoutes)
})
Expand Down Expand Up @@ -411,6 +415,9 @@ func BenchmarkR2router_StaticAll(b *testing.B) {
func BenchmarkRivet_StaticAll(b *testing.B) {
benchRoutes(b, staticRivet, staticRoutes)
}
func BenchmarkSee_StaticAll(b *testing.B) {
benchRoutes(b, staticSee, staticRoutes)
}
func BenchmarkTango_StaticAll(b *testing.B) {
benchRoutes(b, staticTango, staticRoutes)
}
Expand Down