MCPcopy Create free account
hub / github.com/coder/slog / BenchmarkFmt

Function BenchmarkFmt

internal/entryhuman/entry_test.go:335–368  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

333}
334
335func BenchmarkFmt(b *testing.B) {
336 bench := func(b *testing.B, color bool) {
337 nfs := []int{1, 4, 16}
338 for _, nf := range nfs {
339 name := fmt.Sprintf("nf=%v", nf)
340 if color {
341 name = "Colored-" + name
342 }
343 b.Run(name, func(b *testing.B) {
344 fs := make([]slog.Field, nf)
345 for i := 0; i < nf; i++ {
346 fs[i] = slog.F("key", "value")
347 }
348 se := slog.SinkEntry{
349 Level: slog.LevelCritical,
350 Fields: slog.M(
351 fs...,
352 ),
353 }
354 w := io.Discard
355 if color {
356 w = entryhuman.ForceColorWriter
357 }
358 b.ResetTimer()
359 b.ReportAllocs()
360 for i := 0; i < b.N; i++ {
361 entryhuman.Fmt(bytes.NewBuffer(nil), w, se)
362 }
363 })
364 }
365 }
366 bench(b, true)
367 bench(b, false)
368}

Callers

nothing calls this directly

Calls 1

FmtFunction · 0.92

Tested by

no test coverage detected