File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,12 @@ func Ticks() uint64
2323func Cpuid ()
2424
2525// Frequency returns your TSC frequency
26- // will take n*period to find out
26+ // will take the max on "n" tries and
27+ // will take "period" to find out
2728func Frequency (n int , period time.Duration ) float64 {
2829 var startTime , endTime time.Time
2930 var startCounter , endCounter uint64
31+ period /= time .Duration (n )
3032 freq := 0.0
3133 for i := 0 ; i < n ; i ++ {
3234 startTime = time .Now ()
Original file line number Diff line number Diff line change @@ -132,6 +132,18 @@ func TestCPUIDOverhead(t *testing.T) {
132132 Cpuid ()
133133 })
134134}
135+ func TestFrequencySimple (t * testing.T ) {
136+ f := Frequency (1 , time .Second )
137+ t .Logf ("Frequency found: %.2e" , f )
138+ if f <= 0 {
139+ t .Fail ()
140+ }
141+ f = Frequency (maxIter , time .Second )
142+ t .Logf ("Frequency found with %d tries: %.2e" , maxIter , f )
143+ if f <= 0 {
144+ t .Fail ()
145+ }
146+ }
135147func TestFrequency (t * testing.T ) {
136148 s := make ([]float64 , maxIter )
137149 for i := 0 ; i < maxIter ; i ++ {
You can’t perform that action at this time.
0 commit comments