-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathbench_test.go
More file actions
40 lines (35 loc) · 939 Bytes
/
Copy pathbench_test.go
File metadata and controls
40 lines (35 loc) · 939 Bytes
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
package talib
import "testing"
// benchSeries builds a deterministic pseudo-random walk of length n for
// benchmarking window functions. Avoids math/rand so results are stable.
func benchSeries(n int) []float64 {
s := make([]float64, n)
v := 100.0
for i := range s {
// simple deterministic oscillation + drift
v += float64((i*1103515245+12345)%97-48) / 50.0
s[i] = v
}
return s
}
// MidPoint / MidPrice were rewritten from a naive O(n*period) full-window
// rescan to TA-Lib's amortized index-tracking approach. A large period makes
// the difference visible.
func BenchmarkMidPoint(b *testing.B) {
in := benchSeries(5000)
b.ResetTimer()
for i := 0; i < b.N; i++ {
MidPoint(in, 200)
}
}
func BenchmarkMidPrice(b *testing.B) {
high := benchSeries(5000)
low := make([]float64, len(high))
for i := range high {
low[i] = high[i] - 1.0
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
MidPrice(high, low, 200)
}
}