diff --git a/bench_test.go b/bench_test.go index a875ee8..34bba03 100644 --- a/bench_test.go +++ b/bench_test.go @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/github_test.go b/github_test.go index 6f483cd..8588f86 100644 --- a/github_test.go +++ b/github_test.go @@ -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 @@ -375,6 +376,9 @@ func init() { calcMem("LARS", func() { githubLARS = loadLARS(githubAPI) }) + calcMem("Lenrouter", func() { + githubLenrouter = loadLenrouter(githubAPI) + }) calcMem("Macaron", func() { githubMacaron = loadMacaron(githubAPI) }) @@ -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) @@ -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) @@ -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) } diff --git a/go.mod b/go.mod index b911842..dacc012 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 258bc82..cf1f8b0 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/gplus_test.go b/gplus_test.go index b11699a..f407ad4 100644 --- a/gplus_test.go +++ b/gplus_test.go @@ -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 @@ -137,6 +138,9 @@ func init() { calcMem("LARS", func() { gplusLARS = loadLARS(gplusAPI) }) + calcMem("Lenrouter", func() { + gplusLenrouter = loadLenrouter(gplusAPI) + }) calcMem("Macaron", func() { gplusMacaron = loadMacaron(gplusAPI) }) @@ -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) @@ -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) @@ -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) @@ -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) } diff --git a/parse_test.go b/parse_test.go index 51a6520..56d3721 100644 --- a/parse_test.go +++ b/parse_test.go @@ -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 @@ -157,6 +158,9 @@ func init() { calcMem("LARS", func() { parseLARS = loadLARS(parseAPI) }) + calcMem("Lenrouter", func() { + parseLenrouter = loadLenrouter(parseAPI) + }) calcMem("Macaron", func() { parseMacaron = loadMacaron(parseAPI) }) @@ -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) @@ -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) @@ -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) @@ -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) } diff --git a/routers.go b/routers.go index c94f8fe..f4424a3 100644 --- a/routers.go +++ b/routers.go @@ -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" @@ -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() {} diff --git a/routers_test.go b/routers_test.go index ba49233..cdfdb16 100644 --- a/routers_test.go +++ b/routers_test.go @@ -33,6 +33,7 @@ var ( {"HttpTreeMux", loadHttpTreeMux}, //{"Kocha", loadKocha}, {"LARS", loadLARS}, + {"Lenrouter", loadLenrouter}, {"Macaron", loadMacaron}, {"Martini", loadMartini}, {"Pat", loadPat}, diff --git a/static_test.go b/static_test.go index c11823f..d03f61e 100644 --- a/static_test.go +++ b/static_test.go @@ -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 @@ -281,6 +282,9 @@ func init() { calcMem("LARS", func() { staticLARS = loadLARS(staticRoutes) }) + calcMem("Lenrouter", func() { + staticLenrouter = loadLenrouter(staticRoutes) + }) calcMem("Macaron", func() { staticMacaron = loadMacaron(staticRoutes) }) @@ -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) }