benchmarks

Imports

Imports #

"errors"
"log/slog"
"time"
"context"
"fmt"
"io"
"log/slog"
"log/slog/internal/buffer"
"strconv"
"time"

Constants & Variables

testAttrs var #

var testAttrs = []slog.Attr{...}

testDuration var #

var testDuration = *ast.BinaryExpr

testError var #

var testError = *ast.CallExpr

testInt var #

var testInt = 32768

testMessage const #

const testMessage = "Test logging, but use a somewhat realistic message length."

testString var #

var testString = "7e3b3b2aaeff56a7108fe11e154200dd/7819479873059528190"

testTime var #

var testTime = *ast.CallExpr

wantText const #

const wantText = "time=1651363200 level=0 msg=Test logging, but use a somewhat realistic message length. string=7e3b3b2aaeff56a7108fe11e154200dd/7819479873059528190 status=32768 duration=23000000000 time=1651363200 error=fail\n"

Structs

asyncHandler struct #

An asyncHandler simulates a Handler that passes Records to a background goroutine for processing. Because sending to a channel can be expensive due to locking, we simulate a lock-free queue by adding the Record to a ring buffer. Omitting the locking makes this little more than a copy of the Record, but that is a worthwhile thing to measure because Records are on the large side. Since nothing actually reads from the ring buffer, it can handle an arbitrary number of Records without either blocking or allocation.

type asyncHandler struct {
ringBuffer [100]slog.Record
next int
}

disabledHandler struct #

A disabledHandler's Enabled method always returns false.

type disabledHandler struct {

}

fastTextHandler struct #

A fastTextHandler writes a Record to an io.Writer in a format similar to slog.TextHandler, but without quoting or locking. It has a few other performance-motivated shortcuts, like writing times as seconds since the epoch instead of strings. It is intended to represent a high-performance Handler that synchronously writes text (as opposed to binary).

type fastTextHandler struct {
w io.Writer
}

Functions

Enabled method #

func (disabledHandler) Enabled(context.Context, slog.Level) bool

Enabled method #

func (h *fastTextHandler) Enabled(context.Context, slog.Level) bool

Enabled method #

func (*asyncHandler) Enabled(context.Context, slog.Level) bool

Handle method #

func (h *fastTextHandler) Handle(_ context.Context, r slog.Record) error

Handle method #

func (disabledHandler) Handle(context.Context, slog.Record) error

Handle method #

func (h *asyncHandler) Handle(_ context.Context, r slog.Record) error

WithAttrs method #

func (*asyncHandler) WithAttrs([]slog.Attr) slog.Handler

WithAttrs method #

func (h *fastTextHandler) WithAttrs([]slog.Attr) slog.Handler

WithAttrs method #

func (disabledHandler) WithAttrs([]slog.Attr) slog.Handler

WithGroup method #

func (*fastTextHandler) WithGroup(string) slog.Handler

WithGroup method #

func (*asyncHandler) WithGroup(string) slog.Handler

WithGroup method #

func (disabledHandler) WithGroup(string) slog.Handler

appendTime method #

func (h *fastTextHandler) appendTime(buf *buffer.Buffer, t time.Time)

appendValue method #

func (h *fastTextHandler) appendValue(buf *buffer.Buffer, v slog.Value)

newAsyncHandler function #

func newAsyncHandler() *asyncHandler

newFastTextHandler function #

func newFastTextHandler(w io.Writer) slog.Handler

Generated with Arrow