Added Router type
This commit is contained in:
parent
cdcb158623
commit
423a7bfb15
5 changed files with 343 additions and 163 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue