Skip to content

Updating the benchmarks #82

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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.prof
*.res
*.test
.idea
73 changes: 10 additions & 63 deletions bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package main

import (
"io"
"net/http"
"os"
"regexp"
Expand Down Expand Up @@ -96,12 +97,6 @@ func benchRoutes(b *testing.B, router http.Handler, routes []route) {
// Micro Benchmarks

// Route with Param (no write)
func BenchmarkAce_Param(b *testing.B) {
router := loadAceSingle("GET", "/user/:name", aceHandle)

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

Expand Down Expand Up @@ -234,14 +229,8 @@ func BenchmarkR2router_Param(b *testing.B) {
benchRequest(b, router, r)
}

func BenchmarkRevel_Param(b *testing.B) {
router := loadRevelSingle("GET", "/user/:name", "RevelController.Handle")

r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
func BenchmarkRivet_Param(b *testing.B) {
router := loadRivetSingle("GET", "/user/:name", rivetHandler)
func BenchmarkRTE_Param(b *testing.B) {
router := loadRTESingle("GET", "/user/:name", func(w http.ResponseWriter, r *http.Request, _ string) {})

r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
Expand Down Expand Up @@ -283,12 +272,6 @@ const fiveColon = "/:a/:b/:c/:d/:e"
const fiveBrace = "/{a}/{b}/{c}/{d}/{e}"
const fiveRoute = "/test/test/test/test/test"

func BenchmarkAce_Param5(b *testing.B) {
router := loadAceSingle("GET", fiveColon, aceHandle)

r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkBear_Param5(b *testing.B) {
router := loadBearSingle("GET", fiveBrace, bearHandler)

Expand Down Expand Up @@ -420,14 +403,9 @@ func BenchmarkR2router_Param5(b *testing.B) {
benchRequest(b, router, r)
}

func BenchmarkRevel_Param5(b *testing.B) {
router := loadRevelSingle("GET", fiveColon, "RevelController.Handle")

r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkRivet_Param5(b *testing.B) {
router := loadRivetSingle("GET", fiveColon, rivetHandler)
func BenchmarkRTE_Param5(b *testing.B) {
router := loadRTESingle("GET", fiveColon, func(w http.ResponseWriter, r *http.Request, _ [5]string) {
})

r, _ := http.NewRequest("GET", fiveRoute, nil)
benchRequest(b, router, r)
Expand Down Expand Up @@ -469,12 +447,6 @@ const twentyColon = "/:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:
const twentyBrace = "/{a}/{b}/{c}/{d}/{e}/{f}/{g}/{h}/{i}/{j}/{k}/{l}/{m}/{n}/{o}/{p}/{q}/{r}/{s}/{t}"
const twentyRoute = "/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t"

func BenchmarkAce_Param20(b *testing.B) {
router := loadAceSingle("GET", twentyColon, aceHandle)

r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, router, r)
}
func BenchmarkBear_Param20(b *testing.B) {
router := loadBearSingle("GET", twentyBrace, bearHandler)

Expand Down Expand Up @@ -605,19 +577,6 @@ func BenchmarkR2router_Param20(b *testing.B) {
r, _ := http.NewRequest("GET", twentyRoute, nil)
benchRequest(b, router, r)
}

func BenchmarkRevel_Param20(b *testing.B) {
router := loadRevelSingle("GET", twentyColon, "RevelController.Handle")

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

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 @@ -651,12 +610,6 @@ func BenchmarkVulcan_Param20(b *testing.B) {
// }

// Route with Param and write
func BenchmarkAce_ParamWrite(b *testing.B) {
router := loadAceSingle("GET", "/user/:name", aceHandleWrite)

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

Expand Down Expand Up @@ -787,16 +740,10 @@ func BenchmarkR2router_ParamWrite(b *testing.B) {
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}

func BenchmarkRevel_ParamWrite(b *testing.B) {
router := loadRevelSingle("GET", "/user/:name", "RevelController.HandleWrite")

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

func BenchmarkRTE_ParamWrite(b *testing.B) {
router := loadRTESingle("GET", "/user/:name", func(w http.ResponseWriter, r *http.Request, name string) {
io.WriteString(w, name)
})
r, _ := http.NewRequest("GET", "/user/gordon", nil)
benchRequest(b, router, r)
}
Expand Down
48 changes: 9 additions & 39 deletions github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ var githubAPI = []route{
}

var (
githubAce http.Handler
githubBear http.Handler
githubBeego http.Handler
githubBone http.Handler
Expand All @@ -296,8 +295,7 @@ var (
githubPat http.Handler
githubPossum http.Handler
githubR2router http.Handler
githubRevel http.Handler
githubRivet http.Handler
githubRTE http.Handler
githubTango http.Handler
githubTigerTonic http.Handler
githubTraffic http.Handler
Expand All @@ -308,9 +306,6 @@ var (
func init() {
println("#GithubAPI Routes:", len(githubAPI))

calcMem("Ace", func() {
githubAce = loadAce(githubAPI)
})
calcMem("Bear", func() {
githubBear = loadBear(githubAPI)
})
Expand Down Expand Up @@ -374,11 +369,8 @@ func init() {
calcMem("R2router", func() {
githubR2router = loadR2router(githubAPI)
})
calcMem("Revel", func() {
githubRevel = loadRevel(githubAPI)
})
calcMem("Rivet", func() {
githubRivet = loadRivet(githubAPI)
calcMem("RTE", func() {
githubRTE = loadRTE(githubAPI)
})
calcMem("Tango", func() {
githubTango = loadTango(githubAPI)
Expand All @@ -400,10 +392,6 @@ func init() {
}

// Static
func BenchmarkAce_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubAce, req)
}
func BenchmarkBear_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubBear, req)
Expand Down Expand Up @@ -488,13 +476,9 @@ func BenchmarkR2router_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubR2router, req)
}
func BenchmarkRevel_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubRevel, req)
}
func BenchmarkRivet_GithubStatic(b *testing.B) {
func BenchmarkRTE_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
benchRequest(b, githubRivet, req)
benchRequest(b, githubRTE, req)
}
func BenchmarkTango_GithubStatic(b *testing.B) {
req, _ := http.NewRequest("GET", "/user/repos", nil)
Expand All @@ -519,10 +503,6 @@ func BenchmarkVulcan_GithubStatic(b *testing.B) {
// }

// Param
func BenchmarkAce_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubAce, req)
}
func BenchmarkBear_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubBear, req)
Expand Down Expand Up @@ -607,13 +587,9 @@ func BenchmarkR2router_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubR2router, req)
}
func BenchmarkRevel_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubRevel, req)
}
func BenchmarkRivet_GithubParam(b *testing.B) {
func BenchmarkRTE_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
benchRequest(b, githubRivet, req)
benchRequest(b, githubRTE, req)
}
func BenchmarkTango_GithubParam(b *testing.B) {
req, _ := http.NewRequest("GET", "/repos/julienschmidt/httprouter/stargazers", nil)
Expand All @@ -638,9 +614,6 @@ func BenchmarkVulcan_GithubParam(b *testing.B) {
// }

// All routes
func BenchmarkAce_GithubAll(b *testing.B) {
benchRoutes(b, githubAce, githubAPI)
}
func BenchmarkBear_GithubAll(b *testing.B) {
benchRoutes(b, githubBear, githubAPI)
}
Expand Down Expand Up @@ -704,11 +677,8 @@ func BenchmarkPossum_GithubAll(b *testing.B) {
func BenchmarkR2router_GithubAll(b *testing.B) {
benchRoutes(b, githubR2router, githubAPI)
}
func BenchmarkRevel_GithubAll(b *testing.B) {
benchRoutes(b, githubRevel, githubAPI)
}
func BenchmarkRivet_GithubAll(b *testing.B) {
benchRoutes(b, githubRivet, githubAPI)
func BenchmarkRTE_GithubAll(b *testing.B) {
benchRoutes(b, githubRTE, githubAPI)
}
func BenchmarkTango_GithubAll(b *testing.B) {
benchRoutes(b, githubTango, githubAPI)
Expand Down
60 changes: 60 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module github.com/julienschmidt/go-http-routing-benchmark

require (
github.com/Unknwon/com v0.0.0-20190214221849-2d12a219ccaf // indirect
github.com/ant0ine/go-json-rest v3.3.2+incompatible
github.com/astaxie/beego v1.11.1
github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0 // indirect
github.com/dimfeld/httptreemux v5.0.1+incompatible
github.com/emicklei/go-restful v2.9.0+incompatible
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 // indirect
github.com/gin-gonic/gin v1.3.0
github.com/go-macaron/inject v0.0.0-20160627170012-d8a0b8677191 // indirect
github.com/go-macaron/macaron v1.3.2
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab
github.com/go-playground/form v3.1.4+incompatible // indirect
github.com/go-playground/lars v4.0.1+incompatible
github.com/go-zoo/bone v0.0.0-20190117145001-d7ce1372afa7
github.com/gocraft/web v0.0.0-20190207150652-9707327fb69b
github.com/golang/protobuf v1.3.0 // indirect
github.com/gorilla/mux v1.7.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/gravitational/trace v0.0.0-20190218181455-5d6afe38af2b // indirect
github.com/jonboulle/clockwork v0.1.0 // indirect
github.com/json-iterator/go v1.1.5 // indirect
github.com/julienschmidt/httprouter v1.2.0
github.com/jwilner/rte v0.0.0-20190306045212-d83454600b2b
github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.2.8 // indirect
github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de
github.com/lunny/tango v0.5.5
github.com/mailgun/route v0.0.0-20181101151700-58b44163b968
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.6 // indirect
github.com/mikespook/possum v0.0.0-20170224044927-56d7ebb6470b
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/naoina/denco v0.0.0-20180930074809-8475105a6b4c
github.com/naoina/kocha-urlrouter v0.0.0-20140609163054-ad3a6f079210
github.com/pilu/config v0.0.0-20131214182432-3eb99e6c0b9a // indirect
github.com/pilu/miniassert v0.0.0-20140522125902-bee63581261a // indirect
github.com/pilu/traffic v0.5.3
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect
github.com/rcrowley/go-tigertonic v0.0.0-20170420123839-fe6b9f080eb7
github.com/sirupsen/logrus v1.3.0 // indirect
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff // indirect
github.com/stretchr/testify v1.3.0 // indirect
github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43 // indirect
github.com/ursiform/bear v1.0.1
github.com/valyala/fasttemplate v1.0.0 // indirect
github.com/vanng822/r2router v0.0.0-20150523112421-1023140a4f30
github.com/vulcand/predicate v1.1.0 // indirect
github.com/zenazn/goji v0.9.0
goji.io v2.0.2+incompatible
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
gopkg.in/go-playground/validator.v8 v8.18.2 // indirect
gopkg.in/ini.v1 v1.42.0 // indirect
)
Loading