bench_test.go 831 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package restful
  2. import (
  3. "fmt"
  4. "io"
  5. "testing"
  6. )
  7. var uris = []string{}
  8. func setup(container *Container) {
  9. wsCount := 26
  10. rtCount := 26
  11. for i := 0; i < wsCount; i++ {
  12. root := fmt.Sprintf("/%s/{%s}/", string(i+97), string(i+97))
  13. ws := new(WebService).Path(root)
  14. for j := 0; j < rtCount; j++ {
  15. sub := fmt.Sprintf("/%s2/{%s2}", string(j+97), string(j+97))
  16. ws.Route(ws.GET(sub).To(echo))
  17. }
  18. container.Add(ws)
  19. for _, each := range ws.Routes() {
  20. uris = append(uris, "http://bench.com"+each.Path)
  21. }
  22. }
  23. }
  24. func echo(req *Request, resp *Response) {
  25. io.WriteString(resp.ResponseWriter, "echo")
  26. }
  27. func BenchmarkMany(b *testing.B) {
  28. container := NewContainer()
  29. setup(container)
  30. b.ResetTimer()
  31. for t := 0; t < b.N; t++ {
  32. for _, each := range uris {
  33. // println(each)
  34. sendItTo(each, container)
  35. }
  36. }
  37. }