-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark_wcdm_test.go
150 lines (123 loc) · 3.84 KB
/
benchmark_wcdm_test.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package cosmo
import (
"reflect"
"testing"
)
func benchmarkWCDMEN(n int, b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.2, Ol0: 0.7, W0: -1.2}
var z float64
zMax := 1.0
step := zMax / float64(n)
for i := 0; i < b.N; i++ {
for j := 0; j < n; j++ {
z = 0.001 + step*float64(j)
cos.E(z)
}
}
}
func BenchmarkWCDMEN(b *testing.B) {
benchmarkWCDMEN(10000, b)
}
func BenchmarkWCDMENdistance(b *testing.B) {
benchmarkWCDMNdistance(10000, "E", b)
}
func BenchmarkWCDME(b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.2, Ol0: 0.7, W0: -1.2}
z := 1.0
for i := 0; i < b.N; i++ {
cos.E(z)
}
}
func BenchmarkWCDMEinv(b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.2, Ol0: 0.7, W0: -1.2}
z := 1.0
for i := 0; i < b.N; i++ {
cos.Einv(z)
}
}
// benchmarkWCDMDistanceFlat is a helper function to be called by specific benchmarkWCDMs
// for an Omega_K == 0 cosmology
func benchmarkWCDMDistanceFlat(distFunc string, b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.3, Ol0: 0.7, W0: -1}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkWCDMDistancePositiveOk0 is a helper function to be called by specific benchmarkWCDMs
// for an Omega_K > 0 cosmology
func benchmarkWCDMDistancePositiveOk0(distFunc string, b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.3, Ol0: 0.9, W0: -1}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkWCDMDistanceOM is a helper function to be called by specific benchmarkWCDMs
// for an Omega_Lambda = 0 cosmology
func benchmarkWCDMDistanceOM(distFunc string, b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.3, Ol0: 0, W0: -1.2}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkWCDMDistance is a helper function to be called by specific benchmarkWCDMs
func benchmarkWCDMDistance(distFunc string, b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.2, Ol0: 0.7, W0: -1.2}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkWCDMNdistance is a helper function to be called by specific benchmarkWCDMs
func benchmarkWCDMNdistance(n int, distFunc string, b *testing.B) {
cos := WCDM{H0: 70, Om0: 0.2, Ol0: 0.7, W0: -1.2}
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
var z float64
zMax := 1.0
step := zMax / float64(n)
for i := 0; i < b.N; i++ {
for j := 0; j < n; j++ {
z = 0.001 + step*float64(j)
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
}
func BenchmarkWCDMComovingDistance(b *testing.B) {
benchmarkWCDMDistance("ComovingDistance", b)
}
func BenchmarkWCDMComovingTransverseDistance(b *testing.B) {
benchmarkWCDMDistance("ComovingTransverseDistance", b)
}
func BenchmarkWCDMLuminosityDistance(b *testing.B) {
benchmarkWCDMDistance("LuminosityDistance", b)
}
func BenchmarkWCDMLookbackTime(b *testing.B) {
benchmarkWCDMDistance("LookbackTime", b)
}
func BenchmarkWCDMNComovingDistance(b *testing.B) {
benchmarkWCDMNdistance(10000, "ComovingDistance", b)
}
func BenchmarkWCDMNLuminosityDistance(b *testing.B) {
benchmarkWCDMNdistance(10000, "LuminosityDistance", b)
}
func BenchmarkWCDMNE(b *testing.B) {
benchmarkWCDMNdistance(10000, "E", b)
}
func BenchmarkWCDMComovingDistanceOM(b *testing.B) {
benchmarkWCDMDistanceOM("ComovingDistance", b)
}
func BenchmarkWCDMLookbackTimeOM(b *testing.B) {
benchmarkWCDMDistanceOM("LookbackTime", b)
}
func BenchmarkWCDMComovingDistanceFlat(b *testing.B) {
benchmarkWCDMDistanceFlat("ComovingDistance", b)
}
func BenchmarkWCDMComovingDistancePositiveOk0(b *testing.B) {
benchmarkWCDMDistancePositiveOk0("ComovingDistance", b)
}