go test -race -run Test_Path_matchParams
(t *testing.B)
| 346 | |
| 347 | // go test -race -run Test_Path_matchParams |
| 348 | func Benchmark_Path_matchParams(t *testing.B) { |
| 349 | var ctxParams [maxParams]string |
| 350 | benchCaseFn := func(testCollection routeCaseCollection) { |
| 351 | parser := parseRoute(testCollection.pattern, regexp.MustCompile) |
| 352 | for _, c := range testCollection.testCases { |
| 353 | var matchRes bool |
| 354 | state := "match" |
| 355 | if !c.match { |
| 356 | state = "not match" |
| 357 | } |
| 358 | t.Run(testCollection.pattern+"_"+state+"_"+c.url, func(b *testing.B) { |
| 359 | for b.Loop() { |
| 360 | if match := parser.getMatch(c.url, c.url, &ctxParams, c.partialCheck); match { |
| 361 | // Get testCases from the original path |
| 362 | matchRes = true |
| 363 | } |
| 364 | } |
| 365 | require.Equal(t, c.match, matchRes, "route: '%s', url: '%s'", testCollection.pattern, c.url) |
| 366 | if matchRes && len(c.params) > 0 { |
| 367 | require.Equal(t, c.params[0:len(c.params)-1], ctxParams[0:len(c.params)-1], "route: '%s', url: '%s'", testCollection.pattern, c.url) |
| 368 | } |
| 369 | }) |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | for _, testCollection := range benchmarkCases { |
| 374 | benchCaseFn(testCollection) |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | // go test -race -run Test_RoutePatternMatch |
| 379 | func Benchmark_ConstraintExecution(b *testing.B) { |
nothing calls this directly
no test coverage detected