MCPcopy
hub / github.com/gofiber/fiber / Benchmark_Route_Match_Parallel

Function Benchmark_Route_Match_Parallel

router_test.go:2272–2291  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

2270}
2271
2272func Benchmark_Route_Match_Parallel(b *testing.B) {
2273 parsed := parseRoute("/user/keys/:id", regexp.MustCompile)
2274 route := &Route{use: false, root: false, star: false, routeParser: parsed, Params: parsed.params, path: "/user/keys/:id", Path: "/user/keys/:id", Method: "DELETE"}
2275 route.Handlers = append(route.Handlers, func(_ Ctx) error {
2276 return nil
2277 })
2278 b.RunParallel(func(pb *testing.PB) {
2279 // Each worker gets its own local variables to avoid data races
2280 var params [maxParams]string
2281 for pb.Next() {
2282 _ = route.match("/user/keys/1337", "/user/keys/1337", &params)
2283 }
2284 })
2285
2286 // Single-threaded verification to preserve correctness checks
2287 var verifyParams [maxParams]string
2288 match := route.match("/user/keys/1337", "/user/keys/1337", &verifyParams)
2289 require.True(b, match)
2290 require.Equal(b, []string{"1337"}, verifyParams[0:len(parsed.params)])
2291}
2292
2293func Benchmark_Route_Match_Star_Parallel(b *testing.B) {
2294 var match bool

Callers

nothing calls this directly

Calls 3

matchMethod · 0.95
parseRouteFunction · 0.85
NextMethod · 0.65

Tested by

no test coverage detected