56 lines
1.0 KiB
Go
Raw Normal View History

2023-07-09 17:46:17 +02:00
package router_test
import (
"testing"
"git.akyoto.dev/go/router"
)
2023-09-02 09:19:11 +02:00
func BenchmarkBlog(b *testing.B) {
routes := loadRoutes("testdata/blog.txt")
r := router.New[string]()
2023-07-09 17:46:17 +02:00
for _, route := range routes {
2023-09-02 09:19:11 +02:00
r.Add(route.method, route.path, "")
2023-07-09 17:46:17 +02:00
}
2023-09-02 09:19:11 +02:00
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)
}
})
2023-07-09 17:46:17 +02:00
}
2023-09-02 09:19:11 +02:00
func BenchmarkGitHub(b *testing.B) {
2023-07-09 17:46:17 +02:00
routes := loadRoutes("testdata/github.txt")
2023-09-02 09:19:11 +02:00
r := router.New[string]()
2023-07-09 17:46:17 +02:00
for _, route := range routes {
2023-09-02 09:19:11 +02:00
r.Add(route.method, route.path, "")
2023-07-09 17:46:17 +02:00
}
2023-09-02 09:19:11 +02:00
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)
}
})
2023-07-09 17:46:17 +02:00
}