timer

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DEBUG bool = os.Getenv("DEBUG") != ""
)

Functions

This section is empty.

Types

type Timer

type Timer struct {
	Name string

	StageTimes       map[string]time.Time
	StageDurations   map[string]time.Duration
	StagePercentages map[string]string
	Total            int64
	AlignKeys        bool
	Enabled          bool
	// contains filtered or unexported fields
}

Timer is a simple timer that can be used to time the duration of program stages.

func NewTimer

func NewTimer(name string, boolArgs ...bool) *Timer

NewTimer creates a new Timer with the given name. If align is true, values will be vertially aligned in the JSON output

func (*Timer) Mark

func (t *Timer) Mark(stage string)

Mark records the current time as the end of a stage. e.g. to time a block of code: t = NewTimer("MyTimer"); SomeCode(); t.Mark("Some Code");

func (*Timer) PrintJson

func (t *Timer) PrintJson()

Print prints the timer's stage names, durations, and percentages to stderr as indented JSON

func (*Timer) Stop

func (t *Timer) Stop()

Stop records the current time as the end of the last stage, calculates the duration of each stage, the total duration, and the percentage of the total duration that each stage took.

Jump to

Keyboard shortcuts

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