Skip to content
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

add lenrouter #95

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 @@ -234,6 +234,12 @@ func BenchmarkLARS_Param(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkLenrouter_Param(b *testing.B) {
router := loadLenrouterSingle("GET", "/user/:name", lenrouterHandle)

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

Expand Down Expand Up @@ -444,6 +450,12 @@ func BenchmarkLARS_Param5(b *testing.B) {
r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkLenrouter_Param5(b *testing.B) {
router := loadLenrouterSingle("GET", fiveColon, lenrouterHandle)

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

Expand Down Expand Up @@ -654,6 +666,12 @@ func BenchmarkLARS_Param20(b *testing.B) {
r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkLenrouter_Param20(b *testing.B) {
router := loadLenrouterSingle("GET", twentyColon, lenrouterHandle)

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

Expand Down Expand Up @@ -860,6 +878,12 @@ func BenchmarkLARS_ParamWrite(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkLenrouter_ParamWrite(b *testing.B) {
router := loadLenrouterSingle("GET", "/user/:name", lenrouterHandleWrite)

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

Expand Down
15 changes: 15 additions & 0 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ var (
githubHttpTreeMux http.Handler
githubKocha http.Handler
githubLARS http.Handler
githubLenrouter http.Handler
githubMacaron http.Handler
githubMartini http.Handler
githubPat http.Handler
Expand Down Expand Up @@ -375,6 +376,9 @@ func init() {
calcMem("LARS", func() {
githubLARS = loadLARS(githubAPI)
})
calcMem("Lenrouter", func() {
githubLenrouter = loadLenrouter(githubAPI)
})
calcMem("Macaron", func() {
githubMacaron = loadMacaron(githubAPI)
})
Expand Down Expand Up @@ -500,6 +504,10 @@ func BenchmarkLARS_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubLARS, req)
}
func BenchmarkLenrouter_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubLenrouter, req)
}
func BenchmarkMacaron_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubMacaron, req)
Expand Down Expand Up @@ -636,6 +644,10 @@ func BenchmarkLARS_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubLARS, req)
}
func BenchmarkLenrouter_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubLenrouter, req)
}
func BenchmarkMacaron_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubMacaron, req)
Expand Down Expand Up @@ -751,6 +763,9 @@ func BenchmarkKocha_GithubAll(b *testing.B) {
func BenchmarkLARS_GithubAll(b *testing.B) {
benchRoutes(b, githubLARS, githubAPI)
}
func BenchmarkLenrouter_GithubAll(b *testing.B) {
benchRoutes(b, githubLenrouter, githubAPI)
}
func BenchmarkMacaron_GithubAll(b *testing.B) {
benchRoutes(b, githubMacaron, githubAPI)
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
github.com/plimble/ace v0.0.0-20180623113504-ba79f505f416
github.com/plimble/sessions v0.0.0-20180326075456-7047d39da9ad // indirect
github.com/plimble/utils v0.0.0-20150615054616-fe08d46675cd // indirect
github.com/pratikdeoghare/lenrouter v0.0.0-20200820062917-87591fbde452
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 // indirect
github.com/rcrowley/go-tigertonic v0.0.0-20170420123839-fe6b9f080eb7
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ github.com/plimble/utils v0.0.0-20150615054616-fe08d46675cd h1:a/OxgUvo03VLeAIOT
github.com/plimble/utils v0.0.0-20150615054616-fe08d46675cd/go.mod h1:hdBKa62O0OK5mae6xnibGMZRr86u5TM6thzlgxtbEG8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pratikdeoghare/lenrouter v0.0.0-20200820062917-87591fbde452 h1:Mo5gJUxVDBaFsjkhDVjyH/ByqhAdXtxZp8AANhQ0HhA=
github.com/pratikdeoghare/lenrouter v0.0.0-20200820062917-87591fbde452/go.mod h1:o4JAhl3gYLGKGHebMaTYbc10Um1dkxN54p6KbnYX1HA=
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563 h1:dY6ETXrvDG7Sa4vE8ZQG4yqWg6UnOcbqTAahkV813vQ=
github.com/rcrowley/go-metrics v0.0.0-20190826022208-cac0b30c2563/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/rcrowley/go-tigertonic v0.0.0-20170420123839-fe6b9f080eb7 h1:IF6au04LnXfITvXy4gwKKcka4zKYp73RXCEGUACqC/Y=
Expand Down
19 changes: 19 additions & 0 deletions gplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var (
gplusHttpTreeMux http.Handler
gplusKocha http.Handler
gplusLARS http.Handler
gplusLenrouter http.Handler
gplusMacaron http.Handler
gplusMartini http.Handler
gplusPat http.Handler
Expand Down Expand Up @@ -137,6 +138,9 @@ func init() {
calcMem("LARS", func() {
gplusLARS = loadLARS(gplusAPI)
})
calcMem("Lenrouter", func() {
gplusLenrouter = loadLenrouter(gplusAPI)
})
calcMem("Macaron", func() {
gplusMacaron = loadMacaron(gplusAPI)
})
Expand Down Expand Up @@ -262,6 +266,10 @@ func BenchmarkLARS_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusLARS, req)
}
func BenchmarkLenrouter_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusLenrouter, req)
}
func BenchmarkMacaron_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusMacaron, req)
Expand Down Expand Up @@ -398,6 +406,10 @@ func BenchmarkLARS_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusLARS, req)
}
func BenchmarkLenrouter_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusLenrouter, req)
}
func BenchmarkMacaron_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusMacaron, req)
Expand Down Expand Up @@ -534,6 +546,10 @@ func BenchmarkLARS_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusLARS, req)
}
func BenchmarkLenrouter_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusLenrouter, req)
}
func BenchmarkMacaron_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusMacaron, req)
Expand Down Expand Up @@ -649,6 +665,9 @@ func BenchmarkKocha_GPlusAll(b *testing.B) {
func BenchmarkLARS_GPlusAll(b *testing.B) {
benchRoutes(b, gplusLARS, gplusAPI)
}
func BenchmarkLenrouter_GPlusAll(b *testing.B) {
benchRoutes(b, gplusLenrouter, gplusAPI)
}
func BenchmarkMacaron_GPlusAll(b *testing.B) {
benchRoutes(b, gplusMacaron, gplusAPI)
}
Expand Down
19 changes: 19 additions & 0 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ var (
parseHttpTreeMux http.Handler
parseKocha http.Handler
parseLARS http.Handler
parseLenrouter http.Handler
parseMacaron http.Handler
parseMartini http.Handler
parsePat http.Handler
Expand Down Expand Up @@ -157,6 +158,9 @@ func init() {
calcMem("LARS", func() {
parseLARS = loadLARS(parseAPI)
})
calcMem("Lenrouter", func() {
parseLenrouter = loadLenrouter(parseAPI)
})
calcMem("Macaron", func() {
parseMacaron = loadMacaron(parseAPI)
})
Expand Down Expand Up @@ -282,6 +286,10 @@ func BenchmarkLARS_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseLARS, req)
}
func BenchmarkLenrouter_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseLenrouter, req)
}
func BenchmarkMacaron_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseMacaron, req)
Expand Down Expand Up @@ -418,6 +426,10 @@ func BenchmarkLARS_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseLARS, req)
}
func BenchmarkLenrouter_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseLenrouter, req)
}
func BenchmarkMacaron_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseMacaron, req)
Expand Down Expand Up @@ -554,6 +566,10 @@ func BenchmarkLARS_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseLARS, req)
}
func BenchmarkLenrouter_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseLenrouter, req)
}
func BenchmarkMacaron_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseMacaron, req)
Expand Down Expand Up @@ -669,6 +685,9 @@ func BenchmarkKocha_ParseAll(b *testing.B) {
func BenchmarkLARS_ParseAll(b *testing.B) {
benchRoutes(b, parseLARS, parseAPI)
}
func BenchmarkLenrouter_ParseAll(b *testing.B) {
benchRoutes(b, parseLenrouter, parseAPI)
}
func BenchmarkMacaron_ParseAll(b *testing.B) {
benchRoutes(b, parseMacaron, parseAPI)
}
Expand Down
37 changes: 37 additions & 0 deletions routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
_ "github.com/naoina/kocha-urlrouter/doublearray"
"github.com/pilu/traffic"
"github.com/plimble/ace"
"github.com/pratikdeoghare/lenrouter"
"github.com/rcrowley/go-tigertonic"

// "github.com/revel/pathtree"
Expand Down Expand Up @@ -1101,6 +1102,42 @@ func loadLARSSingle(method, path string, h interface{}) http.Handler {
return l.Serve()
}

// lenrouter
func lenrouterHandle(_ http.ResponseWriter, _ *http.Request, _ lenrouter.Params) {}

func lenrouterHandleWrite(w http.ResponseWriter, _ *http.Request, ps lenrouter.Params) {
io.WriteString(w, ps.ByName("name"))
}

func lenrouterHandleTest(w http.ResponseWriter, r *http.Request, _ lenrouter.Params) {
io.WriteString(w, r.RequestURI)
}

func loadLenrouter(routes []route) http.Handler {
h := lenrouterHandle
if loadTestHandler {
h = lenrouterHandleTest
}
var endpoints []lenrouter.Endpoint
for _, route := range routes {
endpoints = append(endpoints, lenrouter.Endpoint{
Method: route.method,
Pattern: route.path,
Handler: h,
})
}

return lenrouter.New(200, 20, endpoints...)
}

func loadLenrouterSingle(method, path string, handle lenrouter.Handle) http.Handler {
return lenrouter.New(200, 20, lenrouter.Endpoint{
Method: method,
Pattern: path,
Handler: handle,
})
}

// Macaron
func macaronHandler() {}

Expand Down
1 change: 1 addition & 0 deletions routers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
{"HttpTreeMux", loadHttpTreeMux},
//{"Kocha", loadKocha},
{"LARS", loadLARS},
{"Lenrouter", loadLenrouter},
{"Macaron", loadMacaron},
{"Martini", loadMartini},
{"Pat", loadPat},
Expand Down
7 changes: 7 additions & 0 deletions static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ var (
staticHttpTreeMux http.Handler
staticKocha http.Handler
staticLARS http.Handler
staticLenrouter http.Handler
staticMacaron http.Handler
staticMartini http.Handler
staticPat http.Handler
Expand Down Expand Up @@ -281,6 +282,9 @@ func init() {
calcMem("LARS", func() {
staticLARS = loadLARS(staticRoutes)
})
calcMem("Lenrouter", func() {
staticLenrouter = loadLenrouter(staticRoutes)
})
calcMem("Macaron", func() {
staticMacaron = loadMacaron(staticRoutes)
})
Expand Down Expand Up @@ -389,6 +393,9 @@ func BenchmarkKocha_StaticAll(b *testing.B) {
func BenchmarkLARS_StaticAll(b *testing.B) {
benchRoutes(b, staticLARS, staticRoutes)
}
func BenchmarkLenrouter_StaticAll(b *testing.B) {
benchRoutes(b, staticLenrouter, staticRoutes)
}
func BenchmarkMacaron_StaticAll(b *testing.B) {
benchRoutes(b, staticMacaron, staticRoutes)
}
Expand Down