performance_test.go 797 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package urn
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. var benchs = []testCase{
  7. tests[14],
  8. tests[2],
  9. tests[6],
  10. tests[10],
  11. tests[11],
  12. tests[13],
  13. tests[20],
  14. tests[23],
  15. tests[33],
  16. tests[45],
  17. tests[47],
  18. tests[48],
  19. tests[50],
  20. tests[52],
  21. tests[53],
  22. tests[57],
  23. tests[62],
  24. tests[63],
  25. tests[67],
  26. tests[60],
  27. }
  28. // This is here to avoid compiler optimizations that
  29. // could remove the actual call we are benchmarking
  30. // during benchmarks
  31. var benchParseResult *URN
  32. func BenchmarkParse(b *testing.B) {
  33. for ii, tt := range benchs {
  34. tt := tt
  35. outcome := (map[bool]string{true: "ok", false: "no"})[tt.ok]
  36. b.Run(
  37. fmt.Sprintf("%s/%02d/%s/", outcome, ii, rxpad(string(tt.in), 45)),
  38. func(b *testing.B) {
  39. for i := 0; i < b.N; i++ {
  40. benchParseResult, _ = Parse(tt.in)
  41. }
  42. },
  43. )
  44. }
  45. }