[common] Add support for determining current nanoseconds runtime.
This commit is contained in:
parent
dbaa404abf
commit
b448af248e
1 changed files with 35 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
|
|
||||||
|
|
||||||
package common
|
package common
|
||||||
|
|
||||||
|
|
||||||
import "reflect"
|
import "reflect"
|
||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
|
@ -61,3 +63,36 @@ func StringToBytes (_input string) ([]byte) {
|
||||||
return _output
|
return _output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: https://github.com/aristanetworks/goarista/blob/master/monotime/nanotime.go
|
||||||
|
|
||||||
|
//go:noescape
|
||||||
|
//go:linkname runtime_nanotime runtime.nanotime
|
||||||
|
func runtime_nanotime () (int64)
|
||||||
|
|
||||||
|
func RuntimeNanoseconds () (uint64) {
|
||||||
|
return uint64 (runtime_nanotime ())
|
||||||
|
}
|
||||||
|
|
||||||
|
func RuntimeMicroseconds () (uint64) {
|
||||||
|
return uint64 (runtime_nanotime ()) / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func RuntimeMilliseconds () (uint64) {
|
||||||
|
return uint64 (runtime_nanotime ()) / 1000 / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func RuntimeSeconds () (uint64) {
|
||||||
|
return uint64 (runtime_nanotime ()) / 1000 / 1000 / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func RuntimeSecondsFloat () (float64) {
|
||||||
|
return float64 (runtime_nanotime ()) / 1000 / 1000 / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func RuntimeHoursFloat () (float64) {
|
||||||
|
return float64 (RuntimeSeconds ()) / 3600
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue