github.com/scaleft/monotime@v0.0.0-20180209174256-2da272f3dad0/monotime.go (about)

     1  package monotime
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  type Timer interface {
     8  	// Returns the elaspsed time since this Timer was created.
     9  	Elapsed() time.Duration
    10  }
    11  
    12  // New creates a portable monotonic timer.  If the underlying system
    13  // changes times, this interface will still return an increasing duration.
    14  func New() Timer {
    15  	return newTimer()
    16  }
    17  
    18  // Now returns the current time from a monotonic clock, it must be
    19  // treated as an opaque, platform specific value.
    20  //
    21  // For most purposes, you should subtract two of these values
    22  // by using the Duration() method.
    23  func Now() Monotime {
    24  	return monotime()
    25  }
    26  
    27  // Duration returns a time.Duration from two previously captured Now() calls.
    28  func Duration(start Monotime, end Monotime) time.Duration {
    29  	return duration(start, end)
    30  }