go test -race -run Test_RoutePatternMatch
(b *testing.B)
| 377 | |
| 378 | // go test -race -run Test_RoutePatternMatch |
| 379 | func Benchmark_ConstraintExecution(b *testing.B) { |
| 380 | var ctxParams [maxParams]string |
| 381 | var match bool |
| 382 | |
| 383 | constraintPatterns := []struct { |
| 384 | name string |
| 385 | pattern string |
| 386 | url string |
| 387 | }{ |
| 388 | {"int", "/api/:id<int>", "/api/12345"}, |
| 389 | {"bool", "/api/:flag<bool>", "/api/true"}, |
| 390 | {"float", "/api/:val<float>", "/api/3.14"}, |
| 391 | {"alpha", "/api/:name<alpha>", "/api/hello"}, |
| 392 | {"guid", "/api/:id<guid>", "/api/12345678-1234-1234-1234-123456789abc"}, |
| 393 | {"minLen", "/api/:name<minLen(3)>", "/api/hello"}, |
| 394 | {"maxLen", "/api/:name<maxLen(10)>", "/api/hello"}, |
| 395 | {"len", "/api/:name<len(5)>", "/api/hello"}, |
| 396 | {"betweenLen", "/api/:name<betweenLen(2,10)>", "/api/hello"}, |
| 397 | {"min", "/api/:id<min(5)>", "/api/10"}, |
| 398 | {"max", "/api/:id<max(100)>", "/api/10"}, |
| 399 | {"range", "/api/:id<range(1,20)>", "/api/10"}, |
| 400 | {"datetime", "/api/:date<datetime(2006-01-02)>", "/api/2024-01-15"}, |
| 401 | {"regex", "/api/:id<regex(^[0-9]+$)>", "/api/12345"}, |
| 402 | } |
| 403 | |
| 404 | for _, tc := range constraintPatterns { |
| 405 | b.Run(tc.name, func(b *testing.B) { |
| 406 | parser := parseRoute(tc.pattern, regexp.MustCompile) |
| 407 | for b.Loop() { |
| 408 | match = parser.getMatch(tc.url, tc.url, &ctxParams, false) |
| 409 | } |
| 410 | }) |
| 411 | } |
| 412 | _ = match |
| 413 | } |
| 414 | |
| 415 | func Benchmark_RoutePatternMatch(t *testing.B) { |
| 416 | benchCaseFn := func(testCollection routeCaseCollection) { |
nothing calls this directly
no test coverage detected