Documentation ¶
Overview ¶
Package timer is a small convenience package for timing blocks of code.
Example ¶
Example of combining a timer with a defer to make it easy to put all your timing code at the top of a function.
defer func(t Timer) { dur := t.Finish() fmt.Printf("log my duration as %g\n", dur) }(Start())
Output:
Example (Block) ¶
Example_block when timing non-funciton based locks, separate the start and finish
// do some work t := Start() // do some more work dur := t.Finish() fmt.Printf("log my duration as %g\n", dur)
Output:
Example (OtherTime) ¶
Example_othertime for when starting from Now isn't quite right
actualStart := time.Unix(1525150486, 0) t := New(actualStart) // do some work dur := t.Finish() fmt.Printf("log my duration as %g\n", dur)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Timer ¶
type Timer interface { // Finish calculates the time since the timer was started and returns its // representation in milliseconds Finish() float64 }
Timer is the thing that you pass around to time blocks of code. Represented as an interface so that other implementations can do fancy things with the values in addition to just returning them, such as submit them to instrumentation frameworks.
Click to show internal directories.
Click to hide internal directories.