File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -324,3 +324,31 @@ func Test_Compile(t *testing.T) {
324324 assert .Equal (t , "mw1" , res .Header .Get ("x-mw1" ), "they should be equal" )
325325 assert .Equal (t , "mw2" , res .Header .Get ("x-mw2" ), "they should be equal" )
326326}
327+
328+ // Benchmark_Compile benchmarks the performance of compiling routes with middleware.
329+ // It sets up an app with multiple routes and groups to simulate real-world usage.
330+ func Benchmark_Compile (b * testing.B ) {
331+ // Setup: create an app with a variety of routes and groups
332+ app := New ()
333+
334+ // Add direct routes
335+ for i := range 50 {
336+ app .Get (fmt .Sprintf ("/route%d" , i ), createTestHandlerFunc (200 , "ok" ))
337+ }
338+
339+ // Add groups with nested routes
340+ for i := range 10 {
341+ g := app .Group (fmt .Sprintf ("/group%d" , i ))
342+ for j := range 10 {
343+ g .Get (fmt .Sprintf ("/sub%d" , j ), createTestHandlerFunc (200 , "ok" ))
344+ }
345+ // Add some middleware to groups for realism
346+ g .Use (createTestMiddlewareHandler ("x-group" , fmt .Sprintf ("group%d" , i )))
347+ }
348+
349+ // Benchmark Compile() - reset the router each iteration to avoid conflicts
350+ for b .Loop () {
351+ app .Router = NewRouter ()
352+ app .Compile ()
353+ }
354+ }
You can’t perform that action at this time.
0 commit comments