| 21 | } |
| 22 | |
| 23 | func 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 | |
| 46 | func BenchmarkWrappedWriteNoHook(b *testing.B) { |
| 47 | w := httptest.NewRecorder() |