Added Router type
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user