github.com/hamba/timex@v1.2.1-0.20240304044353-56d3de3a9ed9/mono/time.go (about)

     1  // Package mono provides a fast monotonic clock source.
     2  package mono
     3  
     4  import (
     5  	"time"
     6  	// Required in order to import nanotime.
     7  	_ "unsafe"
     8  )
     9  
    10  //go:linkname nanotime runtime.nanotime
    11  func nanotime() int64
    12  
    13  // Now returns the current time in nanoseconds from a monotonic clock.
    14  //
    15  // The time returned is guaranteed to increase monotonically at a
    16  // constant rate, unlike timex.Now() which is influenced by NTP
    17  // changes.
    18  func Now() int64 {
    19  	return nanotime()
    20  }
    21  
    22  // Since is analogous to https://golang.org/pkg/time/#Since.
    23  func Since(s int64) time.Duration {
    24  	return time.Duration(Now() - s)
    25  }