timer

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Report

type Report struct {
	// contains filtered or unexported fields
}

Report aggregates timing data for repeated operations.

func NewReport

func NewReport() *Report

NewReport creates an empty Report.

func (*Report) All

func (r *Report) All() []Stats

All returns stats for all labels, sorted by total time descending.

func (*Report) Get

func (r *Report) Get(label string) (Stats, bool)

Get returns stats for a label.

func (*Report) PrintTo

func (r *Report) PrintTo(w io.Writer)

PrintTo writes a formatted table of all stats to w.

func (*Report) Record

func (r *Report) Record(label string, d time.Duration)

Record adds a timing entry. Thread-safe.

func (*Report) Reset

func (r *Report) Reset()

Reset clears all recorded data.

type Stats

type Stats struct {
	Label string
	Count int
	Total time.Duration
	Min   time.Duration
	Max   time.Duration
	Avg   time.Duration
	Last  time.Duration
}

Stats holds aggregate timing statistics for a single label.

type Timer

type Timer struct {
	Label     string
	StartTime time.Time
	EndTime   time.Time
	// contains filtered or unexported fields
}

Timer measures elapsed time for a labeled operation.

func Start

func Start(label string, onStop func(string, time.Duration)) *Timer

Start creates and starts a new Timer.

defer timer.Start("operation", nil).Stop()

func (*Timer) Elapsed

func (t *Timer) Elapsed() time.Duration

Elapsed returns duration since start. If stopped, returns final duration.

func (*Timer) Stop

func (t *Timer) Stop() time.Duration

Stop records the end time and invokes the onStop callback. Safe to call multiple times; subsequent calls are no-ops. Returns the elapsed duration.

func (*Timer) String

func (t *Timer) String() string

String returns "label: 123.456ms".

Jump to

Keyboard shortcuts

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