timings

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: MIT Imports: 3 Imported by: 6

README

go-timings

GoDoc

Several helpers for timing functions or sections of functions. e.g.

func MyFunc() {
  defer timings.Track("MyFunc", timings.Now(), timings.Stderr)
  // Do stuff here
  
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Stdout is a log.Logger that outputs formatted messages to os.Stdout, for convenience.
	Stdout = log.New(os.Stdout, "[TIMING]", log.Lshortfile)
	// Stderr is a log.Logger that outputs formattedd messages to os.Stderr, for convenience.
	Stderr = log.New(os.Stderr, "[TIMING]", log.Lshortfile)
)

Functions

func Now

func Now() time.Time

Now is equivalent to time.Now(), but saves the import of "time" if it's not otherwise needed

func Track

func Track(name string, start time.Time, l *log.Logger)

Track tracks how long a function takes, to a log.Logger e.g. make the first line defer Track("func_name", time.Now(), logger).

func TrackErr

func TrackErr(name string, start time.Time)

TrackErr tracks how long a function takes, to Stderr e.g. make the first line: defer Trackerr("func_name", time.Now()).

func TrackIfLate added in v1.1.0

func TrackIfLate(name string, start time.Time, late time.Duration, l *log.Logger)

TrackIfLate is the same as Track(..), but only prints if the elapsed time is greater than specified.

func TrackOut

func TrackOut(name string, start time.Time)

TrackOut tracks how long a function takes, to Stdout e.g. make the first line: defer TrackOut("func_name", time.Now()).

Types

type Tracker

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

Tracker is a simple device to track timings

func (*Tracker) Duration

func (t *Tracker) Duration() time.Duration

Duration returns the Duration of time between Start() and Stop()

func (*Tracker) Since

func (t *Tracker) Since() time.Duration

Since returns a Duration since the start time

func (*Tracker) Start

func (t *Tracker) Start()

Start records the start time

func (*Tracker) Stop

func (t *Tracker) Stop()

Stop records the end time

Jump to

Keyboard shortcuts

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