mirror of
https://github.com/rclone/rclone.git
synced 2025-01-06 06:20:01 +01:00
28 lines
756 B
Go
28 lines
756 B
Go
package monotime
|
|
|
|
import (
|
|
"syscall"
|
|
"time"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
modkernel32 = syscall.NewLazyDLL("kernel32.dll")
|
|
queryPerformanceFrequencyProc = modkernel32.NewProc("QueryPerformanceFrequency")
|
|
queryPerformanceCounterProc = modkernel32.NewProc("QueryPerformanceCounter")
|
|
|
|
qpcFrequency = queryPerformanceFrequency()
|
|
)
|
|
|
|
func elapsed() time.Duration {
|
|
var elapsed int64
|
|
syscall.Syscall(queryPerformanceCounterProc.Addr(), 1, uintptr(unsafe.Pointer(&elapsed)), 0, 0)
|
|
return time.Duration(elapsed) * time.Second / (time.Duration(qpcFrequency) * time.Nanosecond)
|
|
}
|
|
|
|
func queryPerformanceFrequency() int64 {
|
|
var freq int64
|
|
syscall.Syscall(queryPerformanceFrequencyProc.Addr(), 1, uintptr(unsafe.Pointer(&freq)), 0, 0)
|
|
return freq
|
|
}
|