Reduced memory usage

This commit is contained in:
2023-09-02 09:19:11 +02:00
parent e5b0eb443a
commit 7070897e70
9 changed files with 95 additions and 84 deletions

@ -6,33 +6,50 @@ import (
"git.akyoto.dev/go/router"
)
func BenchmarkLookup(b *testing.B) {
router := router.New[string]()
routes := loadRoutes("testdata/github.txt")
func BenchmarkBlog(b *testing.B) {
routes := loadRoutes("testdata/blog.txt")
r := router.New[string]()
for _, route := range routes {
router.Add(route.method, route.path, "")
r.Add(route.method, route.path, "")
}
b.ResetTimer()
b.Run("Len1-Param0", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/", noop)
}
})
for i := 0; i < b.N; i++ {
router.Lookup("GET", "/repos/:owner/:repo/issues")
}
b.Run("Len1-Param1", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/:id", noop)
}
})
}
func BenchmarkLookupNoAlloc(b *testing.B) {
router := router.New[string]()
func BenchmarkGitHub(b *testing.B) {
routes := loadRoutes("testdata/github.txt")
addParameter := func(string, string) {}
r := router.New[string]()
for _, route := range routes {
router.Add(route.method, route.path, "")
r.Add(route.method, route.path, "")
}
b.ResetTimer()
b.Run("Len7-Param0", func(b *testing.B) {
for i := 0; i < b.N; i++ {
r.LookupNoAlloc("GET", "/issues", noop)
}
})
for i := 0; i < b.N; i++ {
router.LookupNoAlloc("GET", "/repos/:owner/:repo/issues", addParameter)
}
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)
}
})
}