github.com/getlantern/mtime@v0.0.0-20200417132445-23682092d1f7/monotime.go (about) 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 5 // Package mtime provides a fast monotonic clock source. 6 package mtime 7 8 import ( 9 _ "unsafe" // required to use //go:linkname 10 ) 11 12 //go:noescape 13 //go:linkname nanotime runtime.nanotime 14 func nanotime() int64 15 16 // Now returns the current time in nanoseconds from a monotonic clock. 17 // The time returned is based on some arbitrary platform-specific point in the 18 // past. The time returned is guaranteed to increase monotonically at a 19 // constant rate, unlike time.Now() from the Go standard library, which may 20 // slow down, speed up, jump forward or backward, due to NTP activity or leap 21 // seconds. 22 func now() uint64 { 23 return uint64(nanotime()) 24 }