MCPcopy
hub / github.com/rs/zerolog / BenchmarkHandlers

Function BenchmarkHandlers

hlog/hlog_test.go:325–349  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

323}
324
325func BenchmarkHandlers(b *testing.B) {
326 r := &http.Request{
327 Method: "POST",
328 URL: &url.URL{Path: "/path", RawQuery: "foo=bar"},
329 }
330 h1 := URLHandler("url")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
331 l := FromRequest(r)
332 l.Log().Msg("")
333 }))
334 h2 := MethodHandler("method")(RequestHandler("request")(h1))
335 handlers := map[string]http.Handler{
336 "Single": NewHandler(zerolog.New(io.Discard))(h1),
337 "Combined": NewHandler(zerolog.New(io.Discard))(h2),
338 "SingleDisabled": NewHandler(zerolog.New(io.Discard).Level(zerolog.Disabled))(h1),
339 "CombinedDisabled": NewHandler(zerolog.New(io.Discard).Level(zerolog.Disabled))(h2),
340 }
341 for name := range handlers {
342 h := handlers[name]
343 b.Run(name, func(b *testing.B) {
344 for i := 0; i < b.N; i++ {
345 h.ServeHTTP(nil, r)
346 }
347 })
348 }
349}
350
351func BenchmarkDataRace(b *testing.B) {
352 log := zerolog.New(nil).With().

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
URLHandlerFunction · 0.85
FromRequestFunction · 0.85
MethodHandlerFunction · 0.85
RequestHandlerFunction · 0.85
NewHandlerFunction · 0.85
MsgMethod · 0.80
LevelMethod · 0.80
LogMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected