Added tests and benchmarks

This commit is contained in:
2023-07-09 17:46:17 +02:00
parent 1357c04549
commit a05f4b2e36
10 changed files with 330 additions and 29 deletions

38
Benchmarks_test.go Normal file
View File

@ -0,0 +1,38 @@
package router_test
import (
"testing"
"git.akyoto.dev/go/router"
)
func BenchmarkLookup(b *testing.B) {
tree := router.Tree[string]{}
routes := loadRoutes("testdata/github.txt")
for _, route := range routes {
tree.Add(route, "")
}
for i := 0; i < b.N; i++ {
for _, route := range routes {
tree.Lookup(route)
}
}
}
func BenchmarkLookupNoAlloc(b *testing.B) {
tree := router.Tree[string]{}
routes := loadRoutes("testdata/github.txt")
addParameter := func(string, string) {}
for _, route := range routes {
tree.Add(route, "")
}
for i := 0; i < b.N; i++ {
for _, route := range routes {
tree.LookupNoAlloc(route, addParameter)
}
}
}