39 lines
671 B
Go
39 lines
671 B
Go
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)
|
|
}
|
|
}
|
|
}
|