github.com/loov/hrtime@v1.0.3/_example/benchtime/qpc_windows.go (about) 1 package main 2 3 import ( 4 "syscall" 5 "unsafe" 6 ) 7 8 // precision timing 9 var ( 10 modkernel32 = syscall.NewLazyDLL("kernel32.dll") 11 queryPerformanceFrequencyProc = modkernel32.NewProc("QueryPerformanceFrequency") 12 queryPerformanceCounterProc = modkernel32.NewProc("QueryPerformanceCounter") 13 ) 14 15 // now returns time.Duration using queryPerformanceCounter 16 func QPC() int64 { 17 var now int64 18 syscall.Syscall(queryPerformanceCounterProc.Addr(), 1, uintptr(unsafe.Pointer(&now)), 0, 0) 19 return now 20 } 21 22 // QPCFrequency returns frequency in ticks per second 23 func QPCFrequency() int64 { 24 var freq int64 25 r1, _, _ := syscall.Syscall(queryPerformanceFrequencyProc.Addr(), 1, uintptr(unsafe.Pointer(&freq)), 0, 0) 26 if r1 == 0 { 27 panic("call failed") 28 } 29 return freq 30 }