Skip to content

Commit 93e03a0

Browse files
committed
add TestFrequencySimple
1 parent 496e0da commit 93e03a0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

tsc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ func Ticks() uint64
2323
func 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
2728
func 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()

tsc_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}
135147
func TestFrequency(t *testing.T) {
136148
s := make([]float64, maxIter)
137149
for i := 0; i < maxIter; i++ {

0 commit comments

Comments
 (0)