MCPcopy
hub / github.com/caddyserver/caddy / BenchmarkMetricsInstrumentedRoute

Function BenchmarkMetricsInstrumentedRoute

modules/caddyhttp/metrics_test.go:576–598  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

574}
575
576func BenchmarkMetricsInstrumentedRoute(b *testing.B) {
577 ctx, _ := caddy.NewContext(caddy.Context{Context: context.Background()})
578 m := &Metrics{
579 init: sync.Once{},
580 httpMetrics: &httpMetrics{},
581 }
582
583 noopHandler := HandlerFunc(func(w http.ResponseWriter, r *http.Request) error {
584 w.Write([]byte("ok"))
585 return nil
586 })
587
588 ih := newMetricsInstrumentedRoute(ctx, "bench_handler", noopHandler, m)
589
590 r := httptest.NewRequest("GET", "/", nil)
591 w := httptest.NewRecorder()
592
593 b.ResetTimer()
594 b.ReportAllocs()
595 for i := 0; i < b.N; i++ {
596 ih.ServeHTTP(w, r)
597 }
598}
599
600// BenchmarkSingleRouteMetrics simulates the new behavior where metrics
601// are collected once for the entire route.

Callers

nothing calls this directly

Calls 4

HandlerFuncFuncType · 0.85
ServeHTTPMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected