Renamed files
All checks were successful
/ test (push) Successful in 14s

This commit is contained in:
Eduard Urbach 2025-06-06 17:09:28 +02:00
parent 336f317502
commit 06967e1593
Signed by: eduard
GPG key ID: 49226B848C78F6C8
2 changed files with 0 additions and 0 deletions

59
bench_test.go Normal file
View file

@ -0,0 +1,59 @@
package router_test
import (
"testing"
"git.urbach.dev/go/router"
"git.urbach.dev/go/router/testdata"
)
func BenchmarkBlog(b *testing.B) {
routes := testdata.Routes("testdata/blog.txt")
r := router.New[string]()
for _, route := range routes {
r.Add(route.Method, route.Path, "")
}
b.Run("Len1-Param0", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/", noop)
}
})
b.Run("Len1-Param1", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/:id", noop)
}
})
}
func BenchmarkGitHub(b *testing.B) {
routes := testdata.Routes("testdata/github.txt")
r := router.New[string]()
for _, route := range routes {
r.Add(route.Method, route.Path, "")
}
b.Run("Len7-Param0", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/issues", noop)
}
})
b.Run("Len7-Param1", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/gists/:id", noop)
}
})
b.Run("Len7-Param2", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/repos/:owner/:repo/issues", noop)
}
})
}
// noop serves as an empty addParameter function.
func noop(string, string) {}