benchtest

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package benchtest provides shared benchmark helpers for LogLayer transport and framework benchmarks. Mirrors the role of transport/transporttest for contract tests: lets every wrapper-module bench file share a single set of fixtures and runner shapes so the numbers are directly comparable and so per-module copies can't drift.

Index

Constants

View Source
const Msg = "user logged in"

Msg is the standard benchmark message. Use it as the argument to every Info call inside a runner so the per-call payload is constant across modules.

Variables

View Source
var Discard discardWriter

Discard is a no-op io.Writer suitable for any transport whose throughput is being measured. We use this in place of io.Discard because some libraries (charmbracelet/log) detect io.Discard and short-circuit their formatting pipeline; that would understate their real cost. Discard looks like any other writer so every library exercises its full write path.

View Source
var TestUser = User{ID: 42, Name: "Alice", Email: "alice@example.com"}

TestUser is the standard benchmark value passed to every struct- metadata runner.

Functions

func Metadata

func Metadata() loglayer.Metadata

Metadata returns the standard benchmark map[string]any. A fresh map is returned each call so map-mutating plugins under benchmark don't pollute later iterations.

func RunMap

func RunMap(b *testing.B, log *loglayer.LogLayer)

RunMap drives the map-metadata path with a fresh Metadata each iteration.

func RunSimple

func RunSimple(b *testing.B, log *loglayer.LogLayer)

RunSimple drives the simple-message path. The bench reports allocs and resets the timer before the loop.

func RunStruct

func RunStruct(b *testing.B, log *loglayer.LogLayer)

RunStruct drives the struct-metadata path using TestUser.

Types

type User

type User struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

User is the standard benchmark struct. Use TestUser for the pre-populated value; declare a fresh one only when you need to vary the field shapes for a specific scenario.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL