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

Function BenchmarkWrappedWriteWithHook

wrap_bench_test.go:23–44  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

21}
22
23func BenchmarkWrappedWriteWithHook(b *testing.B) {
24 var total int64
25 w := httptest.NewRecorder()
26 ww := Wrap(w, Hooks{
27 Write: func(next WriteFunc) WriteFunc {
28 return func(p []byte) (int, error) {
29 n, err := next(p)
30 total += int64(n)
31 return n, err
32 }
33 },
34 })
35 payload := []byte("hello world")
36 b.ReportAllocs()
37 b.ResetTimer()
38 for i := 0; i < b.N; i++ {
39 _, err := ww.Write(payload)
40 if err != nil {
41 b.Fatal()
42 }
43 }
44}
45
46func BenchmarkWrappedWriteNoHook(b *testing.B) {
47 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 2

WrapFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…