timings

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2023 License: MIT Imports: 3 Imported by: 2

README

timings

import "codeberg.org/mgkeller/go-timings"

Overview

Example :
someLogger := log.New(io.Discard, "[TIMING]", 0)
f := func() {
    defer Track("MyFunc", time.Now(), someLogger)
    // Do stuff here
}

f()
// someLogger will have the timing for the function

Index

Examples
Package files

timings.go

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 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()).

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


Generated by godoc2md

Documentation

Overview

Example
someLogger := log.New(io.Discard, "[TIMING]", 0)
f := func() {
	defer Track("MyFunc", time.Now(), someLogger)
	// Do stuff here
}

f()
// someLogger will have the timing for the function
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

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 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