Skip to content

Add github.com/go-util/router #73

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 @@ -174,6 +174,12 @@ func BenchmarkGorillaMux_Param(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkGoUtilRouter_Param(b *testing.B) {
router := loadGoUtilRouterSingle("GET", "/user/:name", httpHandlerFunc)

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

Expand Down Expand Up @@ -361,6 +367,12 @@ func BenchmarkGorillaMux_Param5(b *testing.B) {
r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkGoUtilRouter_Param5(b *testing.B) {
router := loadGoUtilRouterSingle("GET", fiveColon, httpHandlerFunc)

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

Expand Down Expand Up @@ -547,6 +559,12 @@ func BenchmarkGorillaMux_Param20(b *testing.B) {
r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkGoUtilRouter_Param20(b *testing.B) {
router := loadGoUtilRouterSingle("GET", twentyColon, httpHandlerFunc)

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

Expand Down Expand Up @@ -729,6 +747,12 @@ func BenchmarkGorillaMux_ParamWrite(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkGoUtilRouter_ParamWrite(b *testing.B) {
router := loadGoUtilRouterSingle("GET", "/user/:name", GoUtilRouterHandlerWrite)

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

Expand Down
71 changes: 43 additions & 28 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,34 +274,35 @@ var githubAPI = []route{
}

var (
githubAce http.Handler
githubBear http.Handler
githubBeego http.Handler
githubBone http.Handler
githubDenco http.Handler
githubEcho http.Handler
githubGin http.Handler
githubGocraftWeb http.Handler
githubGoji http.Handler
githubGojiv2 http.Handler
githubGoJsonRest http.Handler
githubGoRestful http.Handler
githubGorillaMux http.Handler
githubHttpRouter http.Handler
githubHttpTreeMux http.Handler
githubKocha http.Handler
githubLARS http.Handler
githubMacaron http.Handler
githubMartini http.Handler
githubPat http.Handler
githubPossum http.Handler
githubR2router http.Handler
githubRevel http.Handler
githubRivet http.Handler
githubTango http.Handler
githubTigerTonic http.Handler
githubTraffic http.Handler
githubVulcan http.Handler
githubAce http.Handler
githubBear http.Handler
githubBeego http.Handler
githubBone http.Handler
githubDenco http.Handler
githubEcho http.Handler
githubGin http.Handler
githubGocraftWeb http.Handler
githubGoji http.Handler
githubGojiv2 http.Handler
githubGoJsonRest http.Handler
githubGoRestful http.Handler
githubGorillaMux http.Handler
githubGoUtilRouter http.Handler
githubHttpRouter http.Handler
githubHttpTreeMux http.Handler
githubKocha http.Handler
githubLARS http.Handler
githubMacaron http.Handler
githubMartini http.Handler
githubPat http.Handler
githubPossum http.Handler
githubR2router http.Handler
githubRevel http.Handler
githubRivet http.Handler
githubTango http.Handler
githubTigerTonic http.Handler
githubTraffic http.Handler
githubVulcan http.Handler
// githubZeus http.Handler
)

Expand Down Expand Up @@ -347,6 +348,9 @@ func init() {
calcMem("GorillaMux", func() {
githubGorillaMux = loadGorillaMux(githubAPI)
})
calcMem("GoUtilRouter", func() {
githubGoUtilRouter = loadGoUtilRouter(githubAPI)
})
calcMem("HttpRouter", func() {
githubHttpRouter = loadHttpRouter(githubAPI)
})
Expand Down Expand Up @@ -452,6 +456,10 @@ func BenchmarkGorillaMux_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubGorillaMux, req)
}
func BenchmarkGoUtilRouter_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubGoUtilRouter, req)
}
func BenchmarkHttpRouter_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubHttpRouter, req)
Expand Down Expand Up @@ -571,6 +579,10 @@ func BenchmarkGorillaMux_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubGorillaMux, req)
}
func BenchmarkGoUtilRouter_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubGoUtilRouter, req)
}
func BenchmarkHttpRouter_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubHttpRouter, req)
Expand Down Expand Up @@ -677,6 +689,9 @@ func BenchmarkGoRestful_GithubAll(b *testing.B) {
func BenchmarkGorillaMux_GithubAll(b *testing.B) {
benchRoutes(b, githubGorillaMux, githubAPI)
}
func BenchmarkGoUtilRouter_GithubAll(b *testing.B) {
benchRoutes(b, githubGoUtilRouter, githubAPI)
}
func BenchmarkHttpRouter_GithubAll(b *testing.B) {
benchRoutes(b, githubHttpRouter, githubAPI)
}
Expand Down
75 changes: 47 additions & 28 deletions gplus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,35 @@ var gplusAPI = []route{
}

var (
gplusAce http.Handler
gplusBear http.Handler
gplusBeego http.Handler
gplusBone http.Handler
gplusDenco http.Handler
gplusEcho http.Handler
gplusGin http.Handler
gplusGocraftWeb http.Handler
gplusGoji http.Handler
gplusGojiv2 http.Handler
gplusGoJsonRest http.Handler
gplusGoRestful http.Handler
gplusGorillaMux http.Handler
gplusHttpRouter http.Handler
gplusHttpTreeMux http.Handler
gplusKocha http.Handler
gplusLARS http.Handler
gplusMacaron http.Handler
gplusMartini http.Handler
gplusPat http.Handler
gplusPossum http.Handler
gplusR2router http.Handler
gplusRevel http.Handler
gplusRivet http.Handler
gplusTango http.Handler
gplusTigerTonic http.Handler
gplusTraffic http.Handler
gplusVulcan http.Handler
gplusAce http.Handler
gplusBear http.Handler
gplusBeego http.Handler
gplusBone http.Handler
gplusDenco http.Handler
gplusEcho http.Handler
gplusGin http.Handler
gplusGocraftWeb http.Handler
gplusGoji http.Handler
gplusGojiv2 http.Handler
gplusGoJsonRest http.Handler
gplusGoRestful http.Handler
gplusGorillaMux http.Handler
gplusGoUtilRouter http.Handler
gplusHttpRouter http.Handler
gplusHttpTreeMux http.Handler
gplusKocha http.Handler
gplusLARS http.Handler
gplusMacaron http.Handler
gplusMartini http.Handler
gplusPat http.Handler
gplusPossum http.Handler
gplusR2router http.Handler
gplusRevel http.Handler
gplusRivet http.Handler
gplusTango http.Handler
gplusTigerTonic http.Handler
gplusTraffic http.Handler
gplusVulcan http.Handler
// gplusZeus http.Handler
)

Expand Down Expand Up @@ -109,6 +110,9 @@ func init() {
calcMem("GorillaMux", func() {
gplusGorillaMux = loadGorillaMux(gplusAPI)
})
calcMem("GoUtilRouter", func() {
gplusGoUtilRouter = loadGoUtilRouter(gplusAPI)
})
calcMem("HttpRouter", func() {
gplusHttpRouter = loadHttpRouter(gplusAPI)
})
Expand Down Expand Up @@ -214,6 +218,10 @@ func BenchmarkGorillaMux_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusGorillaMux, req)
}
func BenchmarkGoUtilRouter_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusGoUtilRouter, req)
}
func BenchmarkHttpRouter_GPlusStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/people", nil)
benchRequest(b, gplusHttpRouter, req)
Expand Down Expand Up @@ -333,6 +341,10 @@ func BenchmarkGorillaMux_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusGorillaMux, req)
}
func BenchmarkGoUtilRouter_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusGoUtilRouter, req)
}
func BenchmarkHttpRouter_GPlusParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327", nil)
benchRequest(b, gplusHttpRouter, req)
Expand Down Expand Up @@ -452,6 +464,10 @@ func BenchmarkGorillaMux_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusGorillaMux, req)
}
func BenchmarkGoUtilRouter_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusGoUtilRouter, req)
}
func BenchmarkHttpRouter_GPlus2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/people/118051310819094153327/activities/123456789", nil)
benchRequest(b, gplusHttpRouter, req)
Expand Down Expand Up @@ -558,6 +574,9 @@ func BenchmarkGoRestful_GPlusAll(b *testing.B) {
func BenchmarkGorillaMux_GPlusAll(b *testing.B) {
benchRoutes(b, gplusGorillaMux, gplusAPI)
}
func BenchmarkGoUtilRouter_GPlusAll(b *testing.B) {
benchRoutes(b, gplusGoUtilRouter, gplusAPI)
}
func BenchmarkHttpRouter_GPlusAll(b *testing.B) {
benchRoutes(b, gplusHttpRouter, gplusAPI)
}
Expand Down
75 changes: 47 additions & 28 deletions parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,34 +56,35 @@ var parseAPI = []route{
}

var (
parseAce http.Handler
parseBear http.Handler
parseBeego http.Handler
parseBone http.Handler
parseDenco http.Handler
parseEcho http.Handler
parseGin http.Handler
parseGocraftWeb http.Handler
parseGoji http.Handler
parseGojiv2 http.Handler
parseGoJsonRest http.Handler
parseGoRestful http.Handler
parseGorillaMux http.Handler
parseHttpRouter http.Handler
parseHttpTreeMux http.Handler
parseKocha http.Handler
parseLARS http.Handler
parseMacaron http.Handler
parseMartini http.Handler
parsePat http.Handler
parsePossum http.Handler
parseR2router http.Handler
parseRevel http.Handler
parseRivet http.Handler
parseTango http.Handler
parseTigerTonic http.Handler
parseTraffic http.Handler
parseVulcan http.Handler
parseAce http.Handler
parseBear http.Handler
parseBeego http.Handler
parseBone http.Handler
parseDenco http.Handler
parseEcho http.Handler
parseGin http.Handler
parseGocraftWeb http.Handler
parseGoji http.Handler
parseGojiv2 http.Handler
parseGoJsonRest http.Handler
parseGoRestful http.Handler
parseGorillaMux http.Handler
parseGoUtilRouter http.Handler
parseHttpRouter http.Handler
parseHttpTreeMux http.Handler
parseKocha http.Handler
parseLARS http.Handler
parseMacaron http.Handler
parseMartini http.Handler
parsePat http.Handler
parsePossum http.Handler
parseR2router http.Handler
parseRevel http.Handler
parseRivet http.Handler
parseTango http.Handler
parseTigerTonic http.Handler
parseTraffic http.Handler
parseVulcan http.Handler
// parseZeus http.Handler
)

Expand Down Expand Up @@ -129,6 +130,9 @@ func init() {
calcMem("GorillaMux", func() {
parseGorillaMux = loadGorillaMux(parseAPI)
})
calcMem("GoUtilRouter", func() {
parseGoUtilRouter = loadGoUtilRouter(parseAPI)
})
calcMem("HttpRouter", func() {
parseHttpRouter = loadHttpRouter(parseAPI)
})
Expand Down Expand Up @@ -234,6 +238,10 @@ func BenchmarkGorillaMux_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseGorillaMux, req)
}
func BenchmarkGoUtilRouter_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseGoUtilRouter, req)
}
func BenchmarkHttpRouter_ParseStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/users", nil)
benchRequest(b, parseHttpRouter, req)
Expand Down Expand Up @@ -353,6 +361,10 @@ func BenchmarkGorillaMux_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseGorillaMux, req)
}
func BenchmarkGoUtilRouter_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseGoUtilRouter, req)
}
func BenchmarkHttpRouter_ParseParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go", nil)
benchRequest(b, parseHttpRouter, req)
Expand Down Expand Up @@ -472,6 +484,10 @@ func BenchmarkGorillaMux_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseGorillaMux, req)
}
func BenchmarkGoUtilRouter_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseGoUtilRouter, req)
}
func BenchmarkHttpRouter_Parse2Params(b *testing.B) {
req, _ := http.NewRequest("GET", "/1/classes/go/123456789", nil)
benchRequest(b, parseHttpRouter, req)
Expand Down Expand Up @@ -578,6 +594,9 @@ func BenchmarkGoRestful_ParseAll(b *testing.B) {
func BenchmarkGorillaMux_ParseAll(b *testing.B) {
benchRoutes(b, parseGorillaMux, parseAPI)
}
func BenchmarkGoUtilRouter_ParseAll(b *testing.B) {
benchRoutes(b, parseGoUtilRouter, parseAPI)
}
func BenchmarkHttpRouter_ParseAll(b *testing.B) {
benchRoutes(b, parseHttpRouter, parseAPI)
}
Expand Down
Loading