Added Router type

This commit is contained in:
2023-07-09 21:24:24 +02:00
parent a05f4b2e36
commit 12b5b4a799
5 changed files with 343 additions and 163 deletions

View File

@ -7,32 +7,36 @@ import (
)
func BenchmarkLookup(b *testing.B) {
tree := router.Tree[string]{}
router := router.New[string]()
routes := loadRoutes("testdata/github.txt")
for _, route := range routes {
tree.Add(route, "")
router.Add(route.method, route.path, "")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, route := range routes {
tree.Lookup(route)
router.Lookup(route.method, route.path)
}
}
}
func BenchmarkLookupNoAlloc(b *testing.B) {
tree := router.Tree[string]{}
router := router.New[string]()
routes := loadRoutes("testdata/github.txt")
addParameter := func(string, string) {}
for _, route := range routes {
tree.Add(route, "")
router.Add(route.method, route.path, "")
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
for _, route := range routes {
tree.LookupNoAlloc(route, addParameter)
router.LookupNoAlloc(route.method, route.path, addParameter)
}
}
}