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