nanotime.go 799 B

123456789101112131415161718192021222324
  1. // Copyright (C) 2016 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. // Package monotime provides a fast monotonic clock source.
  5. package monotime
  6. import (
  7. _ "unsafe" // required to use //go:linkname
  8. )
  9. //go:noescape
  10. //go:linkname nanotime runtime.nanotime
  11. func nanotime() int64
  12. // Now returns the current time in nanoseconds from a monotonic clock.
  13. // The time returned is based on some arbitrary platform-specific point in the
  14. // past. The time returned is guaranteed to increase monotonically at a
  15. // constant rate, unlike time.Now() from the Go standard library, which may
  16. // slow down, speed up, jump forward or backward, due to NTP activity or leap
  17. // seconds.
  18. func Now() Time {
  19. return Time(nanotime())
  20. }