-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark_lambdacdm_test.go
150 lines (123 loc) · 4.02 KB
/
benchmark_lambdacdm_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 benchmarkLambdaCDMEN(n int, b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.9}
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 BenchmarkLambdaCDMEN(b *testing.B) {
benchmarkLambdaCDMEN(10000, b)
}
func BenchmarkLambdaCDMENdistance(b *testing.B) {
benchmarkLambdaCDMNdistance(10000, "E", b)
}
func BenchmarkLambdaCDME(b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.9}
z := 1.0
for i := 0; i < b.N; i++ {
cos.E(z)
}
}
func BenchmarkLambdaCDMEinv(b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.9}
z := 1.0
for i := 0; i < b.N; i++ {
cos.Einv(z)
}
}
// benchmarkLambdaCDMDistanceFlat is a helper function to be called by specific benchmarkLambdaCDMs
// for an Omega_K == 0 cosmology
func benchmarkLambdaCDMDistanceFlat(distFunc string, b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.7}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkLambdaCDMDistancePositiveOk0 is a helper function to be called by specific benchmarkLambdaCDMs
// for an Omega_K > 0 cosmology
func benchmarkLambdaCDMDistancePositiveOk0(distFunc string, b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.9}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkLambdaCDMDistanceOM is a helper function to be called by specific benchmarkLambdaCDMs
// for an Omega_Lambda = 0 cosmology
func benchmarkLambdaCDMDistanceOM(distFunc string, b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.27, Ol0: 0.}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkLambdaCDMDistance is a helper function to be called by specific benchmarkLambdaCDMs
func benchmarkLambdaCDMDistance(distFunc string, b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.9}
z := 1.0
funcToTest := reflect.ValueOf(&cos).MethodByName(distFunc)
for i := 0; i < b.N; i++ {
funcToTest.Call([]reflect.Value{reflect.ValueOf(z)})
}
}
// benchmarkLambdaCDMNdistance is a helper function to be called by specific benchmarkLambdaCDMs
func benchmarkLambdaCDMNdistance(n int, distFunc string, b *testing.B) {
cos := LambdaCDM{H0: 70, Om0: 0.3, Ol0: 0.9}
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 BenchmarkLambdaCDMComovingDistance(b *testing.B) {
benchmarkLambdaCDMDistance("ComovingDistance", b)
}
func BenchmarkLambdaCDMComovingTransverseDistance(b *testing.B) {
benchmarkLambdaCDMDistance("ComovingTransverseDistance", b)
}
func BenchmarkLambdaCDMLuminosityDistance(b *testing.B) {
benchmarkLambdaCDMDistance("LuminosityDistance", b)
}
func BenchmarkLambdaCDMLookbackTime(b *testing.B) {
benchmarkLambdaCDMDistance("LookbackTime", b)
}
func BenchmarkLambdaCDMNComovingDistance(b *testing.B) {
benchmarkLambdaCDMNdistance(10000, "ComovingDistance", b)
}
func BenchmarkLambdaCDMNLuminosityDistance(b *testing.B) {
benchmarkLambdaCDMNdistance(10000, "LuminosityDistance", b)
}
func BenchmarkLambdaCDMNE(b *testing.B) {
benchmarkLambdaCDMNdistance(10000, "E", b)
}
func BenchmarkLambdaCDMComovingDistanceOM(b *testing.B) {
benchmarkLambdaCDMDistanceOM("ComovingDistance", b)
}
func BenchmarkLambdaCDMLookbackTimeOM(b *testing.B) {
benchmarkLambdaCDMDistanceOM("LookbackTime", b)
}
func BenchmarkLambdaCDMComovingDistanceFlat(b *testing.B) {
benchmarkLambdaCDMDistanceFlat("ComovingDistance", b)
}
func BenchmarkLambdaCDMComovingDistancePositiveOk0(b *testing.B) {
benchmarkLambdaCDMDistancePositiveOk0("ComovingDistance", b)
}