github.com/rogpeppe/clock@v0.0.0-20190514195947-2896927a307a/monotonic/monotonic.go (about)

     1  // Copyright 2017 Canonical Ltd.
     2  // Licensed under the LGPLv3, see LICENCE file for details.
     3  
     4  package monotonic
     5  
     6  import (
     7  	"time"
     8  	_ "unsafe"
     9  )
    10  
    11  //go:noescape
    12  //go:linkname nanotime runtime.nanotime
    13  func nanotime() int64
    14  
    15  // Now returns the current time in nanoseconds from a monotonic clock.
    16  //
    17  // The result is guaranteed to not jump due to NTP or other changes to
    18  // system time, which may jump forward or backwards. Instead, in response to
    19  // such changes, the clock frequency is adjusted slowly.
    20  func Now() time.Duration {
    21  	return time.Duration(nanotime())
    22  }