comparison benchmark/benchmarks.jl @ 1858:4a9be96f2569 feature/documenter_logo

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 12 Jan 2025 21:18:44 +0100
parents 471a948cd2b2
children
comparison
equal deleted inserted replaced
1857:ffde7dad9da5 1858:4a9be96f2569
1 using BenchmarkTools
2
3 using Diffinitive
4 using Diffinitive.Grids
5 using Diffinitive.SbpOperators
6 using Diffinitive.LazyTensors
7
8 using LinearAlgebra
9
10 const SUITE = BenchmarkGroup()
11
12
13 sz(d) = ntuple(i->100, d)
14 ll(d) = ntuple(i->0., d)
15 lu(d) = ntuple(i->1., d)
16
17 g1 = equidistant_grid(ll(1)[1], lu(1)[1], sz(1)...)
18 g2 = equidistant_grid(ll(2), lu(2), sz(2)...)
19 g3 = equidistant_grid(ll(3), lu(3), sz(3)...)
20
21 v1 = rand(sz(1)...)
22 v2 = rand(sz(2)...)
23 v3 = rand(sz(3)...)
24
25 u1 = rand(sz(1)...)
26 u2 = rand(sz(2)...)
27 u3 = rand(sz(3)...)
28
29 stencil_set = read_stencil_set(joinpath(sbp_operators_path(),"standard_diagonal.toml"); order=4)
30
31 SUITE["derivatives"] = BenchmarkGroup()
32
33
34 SUITE["derivatives"]["first_derivative"] = BenchmarkGroup()
35
36 D₁ = first_derivative(g1,stencil_set)
37 SUITE["derivatives"]["first_derivative"]["1D"] = @benchmarkable $u1 .= $D₁*$v1
38
39 Dx = first_derivative(g2,stencil_set,1)
40 Dy = first_derivative(g2,stencil_set,2)
41 SUITE["derivatives"]["first_derivative"]["2D"] = BenchmarkGroup()
42 SUITE["derivatives"]["first_derivative"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2
43 SUITE["derivatives"]["first_derivative"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2
44
45 Dx = first_derivative(g3,stencil_set,1)
46 Dy = first_derivative(g3,stencil_set,2)
47 Dz = first_derivative(g3,stencil_set,3)
48 SUITE["derivatives"]["first_derivative"]["3D"] = BenchmarkGroup()
49 SUITE["derivatives"]["first_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3
50 SUITE["derivatives"]["first_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3
51 SUITE["derivatives"]["first_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3
52
53
54 SUITE["derivatives"]["second_derivative"] = BenchmarkGroup()
55
56 D₂ = second_derivative(g1,stencil_set)
57 SUITE["derivatives"]["second_derivative"]["1D"] = @benchmarkable $u1 .= $D₂*$v1
58
59 Dx = second_derivative(g2,stencil_set,1)
60 Dy = second_derivative(g2,stencil_set,2)
61 SUITE["derivatives"]["second_derivative"]["2D"] = BenchmarkGroup()
62 SUITE["derivatives"]["second_derivative"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2
63 SUITE["derivatives"]["second_derivative"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2
64
65 Dx = second_derivative(g3,stencil_set,1)
66 Dy = second_derivative(g3,stencil_set,2)
67 Dz = second_derivative(g3,stencil_set,3)
68 SUITE["derivatives"]["second_derivative"]["3D"] = BenchmarkGroup()
69 SUITE["derivatives"]["second_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3
70 SUITE["derivatives"]["second_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3
71 SUITE["derivatives"]["second_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3
72
73
74 SUITE["derivatives"]["second_derivative_variable"] = BenchmarkGroup()
75
76 c1 = map(x->sin(x)+2, g1)
77 D₂ = second_derivative_variable(g1, c1, stencil_set)
78 SUITE["derivatives"]["second_derivative_variable"]["1D"] = @benchmarkable $u1 .= $D₂*$v1
79
80 c2 = map(x->sin(x[1] + x[2])+2, g2)
81 Dx = second_derivative_variable(g2, c2, stencil_set, 1)
82 Dy = second_derivative_variable(g2, c2, stencil_set, 2)
83 SUITE["derivatives"]["second_derivative_variable"]["2D"] = BenchmarkGroup()
84 SUITE["derivatives"]["second_derivative_variable"]["2D"]["x"] = @benchmarkable $u2 .= $Dx*$v2
85 SUITE["derivatives"]["second_derivative_variable"]["2D"]["y"] = @benchmarkable $u2 .= $Dy*$v2
86
87 c3 = map(x->sin(norm(x))+2, g3)
88 Dx = second_derivative_variable(g3, c3, stencil_set, 1)
89 Dy = second_derivative_variable(g3, c3, stencil_set, 2)
90 Dz = second_derivative_variable(g3, c3, stencil_set, 3)
91 SUITE["derivatives"]["second_derivative_variable"]["3D"] = BenchmarkGroup()
92 SUITE["derivatives"]["second_derivative_variable"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3
93 SUITE["derivatives"]["second_derivative_variable"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3
94 SUITE["derivatives"]["second_derivative_variable"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3
95
96
97
98
99 SUITE["derivatives"]["addition"] = BenchmarkGroup()
100
101 D₁ = first_derivative(g1,stencil_set)
102 D₂ = second_derivative(g1,stencil_set)
103 SUITE["derivatives"]["addition"]["1D"] = BenchmarkGroup()
104 SUITE["derivatives"]["addition"]["1D"]["apply,add"] = @benchmarkable $u1 .= $D₁*$v1 + $D₂*$v1
105 SUITE["derivatives"]["addition"]["1D"]["add,apply"] = @benchmarkable $u1 .= ($D₁ + $D₂)*$v1
106
107 Dxx = second_derivative(g2,stencil_set,1)
108 Dyy = second_derivative(g2,stencil_set,2)
109 SUITE["derivatives"]["addition"]["2D"] = BenchmarkGroup()
110 SUITE["derivatives"]["addition"]["2D"]["apply,add"] = @benchmarkable $u2 .= $Dxx*$v2 + $Dyy*$v2
111 SUITE["derivatives"]["addition"]["2D"]["add,apply"] = @benchmarkable $u2 .= ($Dxx + $Dyy)*$v2
112
113 Dxx = second_derivative(g3,stencil_set,1)
114 Dyy = second_derivative(g3,stencil_set,2)
115 Dzz = second_derivative(g3,stencil_set,3)
116 SUITE["derivatives"]["addition"]["3D"] = BenchmarkGroup()
117 SUITE["derivatives"]["addition"]["3D"]["apply,add"] = @benchmarkable $u3 .= $Dxx*$v3 + $Dyy*$v3 + $Dzz*$v3
118 SUITE["derivatives"]["addition"]["3D"]["add,apply"] = @benchmarkable $u3 .= ($Dxx + $Dyy + $Dzz)*$v3
119
120
121 SUITE["derivatives"]["composition"] = BenchmarkGroup()
122
123 Dx = first_derivative(g1,stencil_set)
124 SUITE["derivatives"]["composition"]["1D"] = BenchmarkGroup()
125 SUITE["derivatives"]["composition"]["1D"]["apply,apply"] = @benchmarkable $u1 .= $Dx*($Dx*$v1)
126 SUITE["derivatives"]["composition"]["1D"]["compose,apply"] = @benchmarkable $u1 .= ($Dx∘$Dx)*$v1
127
128 Dx = first_derivative(g2,stencil_set,1)
129 Dy = first_derivative(g2,stencil_set,2)
130 SUITE["derivatives"]["composition"]["2D"] = BenchmarkGroup()
131 SUITE["derivatives"]["composition"]["2D"]["apply,apply"] = @benchmarkable $u2 .= $Dy*($Dx*$v2)
132 SUITE["derivatives"]["composition"]["2D"]["compose,apply"] = @benchmarkable $u2 .= ($Dy∘$Dx)*$v2
133
134 Dx = first_derivative(g3,stencil_set,1)
135 Dy = first_derivative(g3,stencil_set,2)
136 Dz = first_derivative(g3,stencil_set,3)
137 SUITE["derivatives"]["composition"]["3D"] = BenchmarkGroup()
138 SUITE["derivatives"]["composition"]["3D"]["xy"] = BenchmarkGroup()
139 SUITE["derivatives"]["composition"]["3D"]["xy"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dy*$v3)
140 SUITE["derivatives"]["composition"]["3D"]["xy"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dy)*$v3
141
142 SUITE["derivatives"]["composition"]["3D"]["yz"] = BenchmarkGroup()
143 SUITE["derivatives"]["composition"]["3D"]["yz"]["apply,apply"] = @benchmarkable $u3 .= $Dy*($Dz*$v3)
144 SUITE["derivatives"]["composition"]["3D"]["yz"]["compose,apply"] = @benchmarkable $u3 .= ($Dy∘$Dz)*$v3
145
146 SUITE["derivatives"]["composition"]["3D"]["xz"] = BenchmarkGroup()
147 SUITE["derivatives"]["composition"]["3D"]["xz"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dz*$v3)
148 SUITE["derivatives"]["composition"]["3D"]["xz"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dz)*$v3
149
150 SUITE["derivatives"]["composition"]["3D"]["xx"] = BenchmarkGroup()
151 SUITE["derivatives"]["composition"]["3D"]["xx"]["apply,apply"] = @benchmarkable $u3 .= $Dx*($Dx*$v3)
152 SUITE["derivatives"]["composition"]["3D"]["xx"]["compose,apply"] = @benchmarkable $u3 .= ($Dx∘$Dx)*$v3
153
154 SUITE["derivatives"]["composition"]["3D"]["yy"] = BenchmarkGroup()
155 SUITE["derivatives"]["composition"]["3D"]["yy"]["apply,apply"] = @benchmarkable $u3 .= $Dy*($Dy*$v3)
156 SUITE["derivatives"]["composition"]["3D"]["yy"]["compose,apply"] = @benchmarkable $u3 .= ($Dy∘$Dy)*$v3
157
158 SUITE["derivatives"]["composition"]["3D"]["zz"] = BenchmarkGroup()
159 SUITE["derivatives"]["composition"]["3D"]["zz"]["apply,apply"] = @benchmarkable $u3 .= $Dz*($Dz*$v3)
160 SUITE["derivatives"]["composition"]["3D"]["zz"]["compose,apply"] = @benchmarkable $u3 .= ($Dz∘$Dz)*$v3
161
162
163 SUITE["boundary_terms"] = BenchmarkGroup()
164
165 H = inner_product(g2, stencil_set)
166 H⁻¹ = inverse_inner_product(g2, stencil_set)
167 Dxx = second_derivative(g2, stencil_set, 1)
168 Dyy = second_derivative(g2, stencil_set, 2)
169
170 e₁ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,LowerBoundary}())
171 e₁ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,UpperBoundary}())
172 e₂ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,LowerBoundary}())
173 e₂ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,UpperBoundary}())
174
175 d₁ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{1,LowerBoundary}())
176 d₁ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{1,UpperBoundary}())
177 d₂ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{2,LowerBoundary}())
178 d₂ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{2,UpperBoundary}())
179
180 H₁ₗ = inner_product(boundary_grid(g2, CartesianBoundary{1,LowerBoundary}()), stencil_set)
181 H₁ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{1,UpperBoundary}()), stencil_set)
182 H₂ₗ = inner_product(boundary_grid(g2, CartesianBoundary{2,LowerBoundary}()), stencil_set)
183 H₂ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{2,UpperBoundary}()), stencil_set)
184
185 SUITE["boundary_terms"]["pre_composition"] = @benchmarkable $u2 .= $(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ)*$v2
186 SUITE["boundary_terms"]["composition"] = @benchmarkable $u2 .= ($H⁻¹∘$e₁ₗ'∘$H₁ₗ∘$d₁ₗ)*$v2
187 SUITE["boundary_terms"]["application"] = @benchmarkable $u2 .= $H⁻¹*$e₁ₗ'*$H₁ₗ* $d₁ₗ*$v2
188 # An investigation of these allocations can be found in the branch `allocation_test`
189
190 #TODO: Reorg with dimension as first level? To reduce operator creation?
191
192
193
194 SUITE["lazy_tensors"] = BenchmarkGroup()
195
196 SUITE["lazy_tensors"]["compositions"] = BenchmarkGroup()
197 s = ScalingTensor(1.,(10,))
198 u = rand(10)
199 v = similar(u)
200 s3 = s∘s∘s
201 s4 = s∘s∘s∘s
202 SUITE["lazy_tensors"]["compositions"]["s∘s∘s"] = @benchmarkable $v .= $s3*$u
203 SUITE["lazy_tensors"]["compositions"]["s∘s∘s∘s"] = @benchmarkable $v .= $s4*$u
204
205
206 SUITE