github.com/loov/hrtime@v1.0.3/init.go (about) 1 // Package hrtime implements High-Resolution Timing functions for benchmarking. 2 // 3 // `hrtime` relies on using the best timing mechanism on a particular system. 4 // At the moment, for Windows it is using Performance Counters and on other 5 // platforms standard `time.Now` (since it's good enough). 6 // 7 // Package also supports using hardware time stamp counters (TSC). 8 // They offer better accuracy and on some platforms correspond to the processor cycles. 9 // However, they are not supported on all platforms. 10 // 11 // The basic usage of this package looks like: 12 // 13 // package main 14 // 15 // import ( 16 // "fmt" 17 // "github.com/loov/hrtime" 18 // ) 19 // 20 // func main() { 21 // const numberOfExperiments = 4096 22 // bench := hrtime.NewBenchmark(numberOfExperiments) 23 // for bench.Next() { 24 // time.Sleep(10) 25 // } 26 // fmt.Println(bench.Histogram(10)) 27 // } 28 // 29 // To see more complex examples refer to the _example folder. (https://github.com/loov/hrtime/tree/master/_example) 30 package hrtime 31 32 const calibrationCalls = 1 << 10 33 34 func init() { 35 calculateNanosOverhead() 36 37 initCPU() 38 { 39 _, _, _, edx := cpuid(0x80000007, 0x0) 40 rdtscpInvariant = edx&(1<<8) != 0 41 } 42 calculateTSCOverhead() 43 }