MCPcopy Create free account
hub / github.com/felixge/httpsnoop / benchmark

Function benchmark

capture_metrics_bench_test.go:21–40  ·  view source on GitHub ↗
(b *testing.B, wrappings int)

Source from the content-addressed store, hash-verified

19}
20
21func benchmark(b *testing.B, wrappings int) {
22 dummyH := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
23 h := dummyH
24 for x := 0; x < wrappings; x++ {
25 hCopy := h
26 h = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
27 CaptureMetrics(hCopy, w, r)
28 })
29 }
30
31 req := httptest.NewRequest(http.MethodGet, "/", http.NoBody)
32 resp := httptest.NewRecorder() // ok to reuse; we're not writing anything to it
33
34 b.ReportAllocs()
35 b.ResetTimer()
36
37 for i := 0; i < b.N; i++ {
38 h.ServeHTTP(resp, req)
39 }
40}

Callers 3

BenchmarkBaselineFunction · 0.85
BenchmarkCaptureMetricsFunction · 0.85

Calls 1

CaptureMetricsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…