Skip to content

Commit eb90915

Browse files
new benchmarks (#53)
1 parent 942d1fb commit eb90915

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

bench/benchmark_estimate.jl

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ using ScoreDrivenModels, Distributions, BenchmarkTools, Random, Test
22

33
include("test/utils.jl")
44

5+
scaling = 0.0
6+
ω = [0.1, 0.1]
7+
A = [0.2 0; 0 0.2]
8+
B = [0.2 0; 0 0.2]
9+
simulation = simulate_GAS_1_1(Beta, scaling, ω, A, B, 1)
10+
gas = GAS(1, 1, Beta, scaling)
11+
gas.ω = ω
12+
gas.A[1] = A
13+
gas.B[1] = B
14+
@benchmark score_driven_recursion($gas, $simulation)
15+
# BenchmarkTools.Trial:
16+
# memory estimate: 235.38 KiB
17+
# allocs estimate: 18
18+
# --------------
19+
# minimum time: 999.374 μs (0.00% GC)
20+
# median time: 1.006 ms (0.00% GC)
21+
# mean time: 1.050 ms (1.74% GC)
22+
# maximum time: 55.351 ms (98.06% GC)
23+
# --------------
24+
# samples: 4756
25+
# evals/sample: 1
26+
527
scaling = 0.0
628
ω = [0.1, 0.1]
729
A = [0.2 0; 0 0.2]
@@ -17,13 +39,13 @@ num_seeds = 3
1739
fit!(gas, $simulation; verbose = $verbose, opt_method = opt_method)
1840
end
1941
# BenchmarkTools.Trial:
20-
# memory estimate: 466.69 MiB
21-
# allocs estimate: 40237
42+
# memory estimate: 516.71 MiB
43+
# allocs estimate: 50679
2244
# --------------
23-
# minimum time: 2.553 s (0.57% GC)
24-
# median time: 2.655 s (0.59% GC)
25-
# mean time: 2.655 s (0.59% GC)
26-
# maximum time: 2.756 s (0.60% GC)
45+
# minimum time: 2.857 s (2.91% GC)
46+
# median time: 2.927 s (1.71% GC)
47+
# mean time: 2.927 s (1.71% GC)
48+
# maximum time: 2.997 s (0.57% GC)
2749
# --------------
2850
# samples: 2
2951
# evals/sample: 1
@@ -43,13 +65,13 @@ num_seeds = 3
4365
fit!(gas, $simulation; verbose = $verbose, opt_method = opt_method)
4466
end
4567
# BenchmarkTools.Trial:
46-
# memory estimate: 353.02 MiB
47-
# allocs estimate: 30598
68+
# memory estimate: 386.33 MiB
69+
# allocs estimate: 38084
4870
# --------------
49-
# minimum time: 1.008 s (1.41% GC)
50-
# median time: 1.265 s (1.36% GC)
51-
# mean time: 1.281 s (1.35% GC)
52-
# maximum time: 1.587 s (1.28% GC)
71+
# minimum time: 1.014 s (1.15% GC)
72+
# median time: 1.358 s (1.13% GC)
73+
# mean time: 1.341 s (2.56% GC)
74+
# maximum time: 1.632 s (1.12% GC)
5375
# --------------
5476
# samples: 4
5577
# evals/sample: 1
@@ -62,15 +84,15 @@ scaling = 0.5
6284
fit!(gas, $simulation; verbose = $verbose, opt_method = opt_method)
6385
end
6486
# BenchmarkTools.Trial:
65-
# memory estimate: 8.26 GiB
66-
# allocs estimate: 159942290
87+
# memory estimate: 1.94 GiB
88+
# allocs estimate: 54273958
6789
# --------------
68-
# minimum time: 7.361 s (18.19% GC)
69-
# median time: 7.361 s (18.19% GC)
70-
# mean time: 7.361 s (18.19% GC)
71-
# maximum time: 7.361 s (18.19% GC)
90+
# minimum time: 4.936 s (3.77% GC)
91+
# median time: 6.007 s (4.06% GC)
92+
# mean time: 6.007 s (4.06% GC)
93+
# maximum time: 7.078 s (4.26% GC)
7294
# --------------
73-
# samples: 1
95+
# samples: 2
7496
# evals/sample: 1
7597

7698
scaling = 1.0
@@ -80,13 +102,13 @@ scaling = 1.0
80102
fit!(gas, $simulation; verbose = $verbose, opt_method = opt_method)
81103
end
82104
# BenchmarkTools.Trial:
83-
# memory estimate: 666.69 MiB
84-
# allocs estimate: 8744603
105+
# memory estimate: 750.17 MiB
106+
# allocs estimate: 9849254
85107
# --------------
86-
# minimum time: 2.908 s (2.08% GC)
87-
# median time: 3.382 s (2.07% GC)
88-
# mean time: 3.382 s (2.07% GC)
89-
# maximum time: 3.855 s (2.07% GC)
108+
# minimum time: 3.217 s (1.91% GC)
109+
# median time: 3.320 s (1.91% GC)
110+
# mean time: 3.320 s (1.91% GC)
111+
# maximum time: 3.424 s (1.92% GC)
90112
# --------------
91113
# samples: 2
92114
# evals/sample: 1

src/gas/gas.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,20 @@ function fill_psitilde!(gas::GAS, psitilde::Vector{T}, unknowns::UnknownsGAS) wh
7979
# fill ω
8080
for i in unknowns.ω
8181
offset += 1
82-
gas.ω[i] = psitilde[offset]
82+
@inbounds gas.ω[i] = psitilde[offset]
8383
end
8484
# fill A
8585
for (k, v) in unknowns.A
8686
for i in v
8787
offset += 1
88-
gas.A[k][i] = psitilde[offset]
88+
@inbounds gas.A[k][i] = psitilde[offset]
8989
end
9090
end
9191
# fill B
9292
for (k, v) in unknowns.B
9393
for i in v
9494
offset += 1
95-
gas.B[k][i] = psitilde[offset]
95+
@inbounds gas.B[k][i] = psitilde[offset]
9696
end
9797
end
9898
return

src/gas/univariate_score_driven_recursion.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function score_driven_recursion(gas::GAS{D, T}, observations::Vector{T};
2020
biggest_lag = number_of_lags(gas)
2121

2222
# initial_values
23-
for i in 1:biggest_lag
23+
@inbounds for i in 1:biggest_lag
2424
for p in 1:n_params
2525
param[i, p] = initial_params[i, p]
2626
end
@@ -30,7 +30,7 @@ function score_driven_recursion(gas::GAS{D, T}, observations::Vector{T};
3030

3131
update_param_tilde!(param_tilde, gas.ω, gas.A, gas.B, scores_tilde, biggest_lag)
3232

33-
for i in biggest_lag + 1:n
33+
@inbounds for i in biggest_lag + 1:n
3434
univariate_score_driven_update!(param, param_tilde, scores_tilde, observations[i], aux, gas, i)
3535
end
3636
update_param!(param, param_tilde, D, n + 1)
@@ -59,7 +59,7 @@ function simulate_recursion(gas::GAS{D, T}, n::Int;
5959
# initial_values
6060
for t in 1:biggest_lag
6161
for p in 1:n_params
62-
param[t, p] = initial_params[t, p]
62+
@inbounds param[t, p] = initial_params[t, p]
6363
end
6464
link!(param_tilde, D, param, t)
6565
# Sample
@@ -111,16 +111,16 @@ end
111111
function update_param_tilde!(param_tilde::Matrix{T}, ω::Vector{T}, A::Dict{Int, Matrix{T}},
112112
B::Dict{Int, Matrix{T}}, scores_tilde::Matrix{T}, i::Int) where T
113113
for p in eachindex(ω)
114-
param_tilde[i + 1, p] = ω[p]
114+
@inbounds param_tilde[i + 1, p] = ω[p]
115115
end
116116
for (lag, mat) in A
117117
for p in axes(mat, 1)
118-
param_tilde[i + 1, p] += mat[p, p] * scores_tilde[i - lag + 1, p]
118+
@inbounds param_tilde[i + 1, p] += mat[p, p] * scores_tilde[i - lag + 1, p]
119119
end
120120
end
121121
for (lag, mat) in B
122122
for p in axes(mat, 1)
123-
param_tilde[i + 1, p] += mat[p, p] * param_tilde[i - lag + 1, p]
123+
@inbounds param_tilde[i + 1, p] += mat[p, p] * param_tilde[i - lag + 1, p]
124124
end
125125
end
126126
return

0 commit comments

Comments
 (0)