Updated benchmarks

This commit is contained in:
Eduard Urbach 2024-03-15 12:50:42 +01:00
parent 0fe8514bf0
commit 0793a0197a
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
5 changed files with 32 additions and 68 deletions

View File

@ -1,26 +1,22 @@
# benchmarks # benchmarks
- goos: linux
- goarch: amd64
- cpu: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
## Web ## Web
Router tree with 203 routes (GitHub):
``` ```
BenchmarkAero/Hello-12 26931560 41.81 ns/op 0 B/op 0 allocs/op BenchmarkAero/GitHub-12 14560964 80.22 ns/op 0 B/op 0 allocs/op
BenchmarkAero/GitHub-12 14009696 81.21 ns/op 0 B/op 0 allocs/op BenchmarkAkyoto/GitHub-12 18967251 62.96 ns/op 0 B/op 0 allocs/op
BenchmarkAkyoto/Hello-12 33492621 33.18 ns/op 0 B/op 0 allocs/op BenchmarkBeego/GitHub-12 656966 1656 ns/op 929 B/op 9 allocs/op
BenchmarkAkyoto/GitHub-12 16838250 67.83 ns/op 0 B/op 0 allocs/op BenchmarkBone/GitHub-12 86756 11830 ns/op 4705 B/op 67 allocs/op
BenchmarkBeego/Hello-12 1000000 1102 ns/op 880 B/op 8 allocs/op BenchmarkChi/GitHub-12 3274795 359.6 ns/op 336 B/op 2 allocs/op
BenchmarkBeego/GitHub-12 624705 1662 ns/op 929 B/op 9 allocs/op BenchmarkEcho/GitHub-12 10842609 108.1 ns/op 0 B/op 0 allocs/op
BenchmarkBone/Hello-12 42657504 27.23 ns/op 0 B/op 0 allocs/op BenchmarkGin/GitHub-12 11746930 108.2 ns/op 0 B/op 0 allocs/op
BenchmarkBone/GitHub-12 99516 11865 ns/op 4705 B/op 67 allocs/op BenchmarkJSHR/GitHub-12 9244504 123.1 ns/op 96 B/op 1 allocs/op
BenchmarkChi/Hello-12 3925130 304.0 ns/op 336 B/op 2 allocs/op BenchmarkPat/GitHub-12 20920 83830 ns/op 375238 B/op 235 allocs/op
BenchmarkChi/GitHub-12 3351840 358.3 ns/op 336 B/op 2 allocs/op BenchmarkWay/GitHub-12 117394 9808 ns/op 4979 B/op 177 allocs/op
BenchmarkEcho/Hello-12 22363914 50.36 ns/op 0 B/op 0 allocs/op
BenchmarkEcho/GitHub-12 11246779 108.3 ns/op 0 B/op 0 allocs/op
BenchmarkGin/Hello-12 22194129 53.52 ns/op 0 B/op 0 allocs/op
BenchmarkGin/GitHub-12 12067813 98.31 ns/op 0 B/op 0 allocs/op
BenchmarkJSHR/Hello-12 53599078 21.58 ns/op 0 B/op 0 allocs/op
BenchmarkJSHR/GitHub-12 9453891 123.2 ns/op 96 B/op 1 allocs/op
BenchmarkPat/Hello-12 13931152 84.22 ns/op 48 B/op 1 allocs/op
BenchmarkPat/GitHub-12 20864 84397 ns/op 374291 B/op 235 allocs/op
BenchmarkWay/Hello-12 4725717 252.8 ns/op 307 B/op 3 allocs/op
BenchmarkWay/GitHub-12 119774 9904 ns/op 4979 B/op 177 allocs/op
``` ```

View File

@ -9,7 +9,6 @@ import (
) )
var ( var (
helloRoute = "/"
githubRoute = "/repos/:owner/:repo" githubRoute = "/repos/:owner/:repo"
payloadString = "Hello" payloadString = "Hello"
payload = []byte(payloadString) payload = []byte(payloadString)
@ -25,17 +24,6 @@ func (r *NullResponse) WriteHeader(int) {}
// bench is the core benchmarking function. // bench is the core benchmarking function.
func bench[T http.Handler](b *testing.B, init func() T, addRoute func(T, string, string)) { func bench[T http.Handler](b *testing.B, init func() T, addRoute func(T, string, string)) {
b.Run("Hello", func(b *testing.B) {
request := httptest.NewRequest("GET", helloRoute, nil)
response := &NullResponse{}
router := init()
addRoute(router, "GET", "/")
for range b.N {
router.ServeHTTP(response, request)
}
})
b.Run("GitHub", func(b *testing.B) { b.Run("GitHub", func(b *testing.B) {
request := httptest.NewRequest("GET", githubRoute, nil) request := httptest.NewRequest("GET", githubRoute, nil)
response := &NullResponse{} response := &NullResponse{}

View File

@ -4,7 +4,7 @@ go 1.22.1
require ( require (
git.akyoto.dev/go/router v0.1.3 git.akyoto.dev/go/router v0.1.3
git.akyoto.dev/go/server v0.0.0-20240313230620-594cad69db74 git.akyoto.dev/go/server v0.0.0-20240314115203-fe184c089268
github.com/aerogo/aero v1.3.59 github.com/aerogo/aero v1.3.59
github.com/beego/beego/v2 v2.1.6 github.com/beego/beego/v2 v2.1.6
github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f github.com/bmizerany/pat v0.0.0-20210406213842-e4b6760bdd6f
@ -67,6 +67,6 @@ require (
golang.org/x/net v0.21.0 // indirect golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )

View File

@ -2,8 +2,8 @@ git.akyoto.dev/go/assert v0.1.3 h1:QwCUbmG4aZYsNk/OuRBz1zWVKmGlDUHhOnnDBfn8Qw8=
git.akyoto.dev/go/assert v0.1.3/go.mod h1:0GzMaM0eURuDwtGkJJkCsI7r2aUKr+5GmWNTFPgDocM= git.akyoto.dev/go/assert v0.1.3/go.mod h1:0GzMaM0eURuDwtGkJJkCsI7r2aUKr+5GmWNTFPgDocM=
git.akyoto.dev/go/router v0.1.3 h1:H4wJCYdDD3/i9miYSK/e5sCoGiXe9OX7KmgH4/Toa60= git.akyoto.dev/go/router v0.1.3 h1:H4wJCYdDD3/i9miYSK/e5sCoGiXe9OX7KmgH4/Toa60=
git.akyoto.dev/go/router v0.1.3/go.mod h1:VfSsK/Z6fUhT3pWaAAnuAcj++bWRZD+bzNaqJoTAunU= git.akyoto.dev/go/router v0.1.3/go.mod h1:VfSsK/Z6fUhT3pWaAAnuAcj++bWRZD+bzNaqJoTAunU=
git.akyoto.dev/go/server v0.0.0-20240313230620-594cad69db74 h1:maCXHWOVHEC9A3FGZ6DSlWC5klNWaPA8GZqBAG1xKBk= git.akyoto.dev/go/server v0.0.0-20240314115203-fe184c089268 h1:hJKwhtTMvJKa8ZLHvbL985cRgc3Eujgr5tFbAY1uWKE=
git.akyoto.dev/go/server v0.0.0-20240313230620-594cad69db74/go.mod h1:VVr9rDl+CPnQyXphXpOcpSovrjzPGsSk00PjUBHkx1c= git.akyoto.dev/go/server v0.0.0-20240314115203-fe184c089268/go.mod h1:VVr9rDl+CPnQyXphXpOcpSovrjzPGsSk00PjUBHkx1c=
github.com/aerogo/aero v1.3.59 h1:5yu+kk/uIXAXADKSLCFKhxAzThCehvpbF6gst+G32Fw= github.com/aerogo/aero v1.3.59 h1:5yu+kk/uIXAXADKSLCFKhxAzThCehvpbF6gst+G32Fw=
github.com/aerogo/aero v1.3.59/go.mod h1:ehwj+mb117xQRTvp11jlnrRNPgbcYL6s6aBk9wbIZ0o= github.com/aerogo/aero v1.3.59/go.mod h1:ehwj+mb117xQRTvp11jlnrRNPgbcYL6s6aBk9wbIZ0o=
github.com/aerogo/csp v0.1.10 h1:2PJf9gkdRvCFYOA0baTUyp34vwPp5ZJJX8GZRCYc/nM= github.com/aerogo/csp v0.1.10 h1:2PJf9gkdRvCFYOA0baTUyp34vwPp5ZJJX8GZRCYc/nM=
@ -173,8 +173,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

View File

@ -2,41 +2,21 @@ package main_test
import ( import (
"net/http" "net/http"
"net/http/httptest"
"testing" "testing"
"git.akyoto.dev/go/router/testdata"
"github.com/matryer/way" "github.com/matryer/way"
) )
func BenchmarkWay(b *testing.B) { func BenchmarkWay(b *testing.B) {
response := &NullResponse{} bench(
b,
b.Run("Hello", func(b *testing.B) { func() *way.Router {
request := httptest.NewRequest("GET", helloRoute, nil) return way.NewRouter()
router := way.NewRouter() },
func(r *way.Router, method string, path string) {
router.HandleFunc("GET", "/", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc(method, path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write(payload) w.Write(payload)
}) }))
},
for range b.N { )
router.ServeHTTP(response, request)
}
})
b.Run("GitHub", func(b *testing.B) {
request := httptest.NewRequest("GET", githubRoute, nil)
router := way.NewRouter()
for _, route := range testdata.Routes("testdata/github.txt") {
router.HandleFunc(route.Method, route.Path, func(w http.ResponseWriter, r *http.Request) {
w.Write(payload)
})
}
for range b.N {
router.ServeHTTP(response, request)
}
})
} }