Added tests and benchmarks
This commit is contained in:
38
Benchmarks_test.go
Normal file
38
Benchmarks_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user