43 lines
791 B
Go
Raw Normal View History

2023-07-09 17:46:17 +02:00
package router_test
import (
"testing"
"git.akyoto.dev/go/router"
)
func BenchmarkLookup(b *testing.B) {
2023-07-09 21:24:24 +02:00
router := router.New[string]()
2023-07-09 17:46:17 +02:00
routes := loadRoutes("testdata/github.txt")
for _, route := range routes {
2023-07-09 21:24:24 +02:00
router.Add(route.method, route.path, "")
2023-07-09 17:46:17 +02:00
}
2023-07-09 21:24:24 +02:00
b.ResetTimer()
2023-07-09 17:46:17 +02:00
for i := 0; i < b.N; i++ {
for _, route := range routes {
2023-07-09 21:24:24 +02:00
router.Lookup(route.method, route.path)
2023-07-09 17:46:17 +02:00
}
}
}
func BenchmarkLookupNoAlloc(b *testing.B) {
2023-07-09 21:24:24 +02:00
router := router.New[string]()
2023-07-09 17:46:17 +02:00
routes := loadRoutes("testdata/github.txt")
addParameter := func(string, string) {}
for _, route := range routes {
2023-07-09 21:24:24 +02:00
router.Add(route.method, route.path, "")
2023-07-09 17:46:17 +02:00
}
2023-07-09 21:24:24 +02:00
b.ResetTimer()
2023-07-09 17:46:17 +02:00
for i := 0; i < b.N; i++ {
for _, route := range routes {
2023-07-09 21:24:24 +02:00
router.LookupNoAlloc(route.method, route.path, addParameter)
2023-07-09 17:46:17 +02:00
}
}
}