stopwatch

package module
v0.0.0-...-a58cccc Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: MIT Imports: 2 Imported by: 23

README

stopwatch

A simply package for timing your code. The intention is to provide a simple, light-weight library for benchmarking specific bits of your code when need be.

Example

package main

import (
  "fmt"

  "github.com/bradhe/stopwatch"
)

func main() {
  watch := stopwatch.Start()

  // Do some work.

  watch.Stop()
  fmt.Printf("Milliseconds elapsed: %v\n", watch.Milliseconds())
}

Contributing

  1. Fork and fix/implement in a branch.
  2. Make sure tests pass.
  3. Make sure you've added new coverage.
  4. Submit a PR.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TimerFunc

type TimerFunc func(Watch)

Function prototype for timers.

type Watch

type Watch interface {
	fmt.Stringer

	// Timer calls a callback with the currently-measured time. This is useful for
	// deferring out of a function.
	Timer(fn TimerFunc)

	// Stops the watch based on the current wall-clock time.
	Stop() Watch

	// Starts the watch based on the current wall-clock time.
	Start() Watch

	// Milliseconds returns the elapsed duration in milliseconds.
	Milliseconds() time.Duration

	// Seconds returns the elapsed duration in seconds.
	Seconds() time.Duration

	// Minutes returns the elapsed duration in minutes.
	Minutes() time.Duration

	// Hours returns the elapsed duration in hours.
	Hours() time.Duration

	// Days returns the elapsed duration in days.
	Days() time.Duration
}

func Start

func Start() Watch

Start starts a new Watch for you.

func StartAt

func StartAt(t time.Time) Watch

StartAt starts a new Watch for you at the time supplied. Mostly useful for testing, but could be used to capture other logic within an app or service.

Jump to

Keyboard shortcuts

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