Skip to content

sanwishe/Stopwatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StopWatch

A simple stop watch, allowing for timing of a number of tasks.exposing total running time and running time for each named task. Note that Stopwatch is not designed for mutli-thread use.

Usage

go get github.com/sanwishe/Stopwatch

example usage

import (
    "time"
    "fmt"
    "github.com/sanwishe/Stopwatch"
)

func yourFunc() {
	stopWatch := stopwatch.New("test")

	stopWatch.Start("[<step 1>]")
	time.Sleep(time.Millisecond * 100)
	stopWatch.Stop()

	stopWatch.Start("[<step 2>]")
	time.Sleep(time.Millisecond * 2)
	stopWatch.Stop()

	stopWatch.Start("[<step 3>]")
	time.Sleep(time.Millisecond * 3)
	stopWatch.Stop()

	stopWatch.Start("[<step 4>]")
	time.Sleep(time.Millisecond * 4)
	stopWatch.Stop()

	fmt.Println(stopWatch.PrettyPrint())
}

The example will expose print such as:

StopWatch 'test': running time (ms) = 114
-----------------------------------------
ms        %         Task name
-----------------------------------------
103       90%       [<step 1>]
2         2%        [<step 2>]
3         2%        [<step 3>]
5         4%        [<step 4>]

About

A simple stop watch

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages