comparison benchmark/benchmarks.jl @ 1854:654a2b7e6824 tooling/benchmarks

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 11 Jan 2025 10:19:47 +0100
parents 471a948cd2b2
children
comparison
equal deleted inserted replaced
1378:2b5480e2d4bf 1854:654a2b7e6824
1 using BenchmarkTools 1 using BenchmarkTools
2 using Sbplib 2
3 using Sbplib.Grids 3 using Diffinitive
4 using Sbplib.SbpOperators 4 using Diffinitive.Grids
5 using Sbplib.RegionIndices 5 using Diffinitive.SbpOperators
6 using Sbplib.LazyTensors 6 using Diffinitive.LazyTensors
7
8 using LinearAlgebra
7 9
8 const SUITE = BenchmarkGroup() 10 const SUITE = BenchmarkGroup()
9 11
10 12
11 sz(d) = ntuple(i->100, d) 13 sz(d) = ntuple(i->100, d)
12 ll(d) = ntuple(i->0., d) 14 ll(d) = ntuple(i->0., d)
13 lu(d) = ntuple(i->1., d) 15 lu(d) = ntuple(i->1., d)
14 16
15 g1 = equidistant_grid(sz(1)[1],ll(1)[1],lu(1)[1]) 17 g1 = equidistant_grid(ll(1)[1], lu(1)[1], sz(1)...)
16 g2 = equidistant_grid(sz(2),ll(2),lu(2)) 18 g2 = equidistant_grid(ll(2), lu(2), sz(2)...)
17 g3 = equidistant_grid(sz(3),ll(3),lu(3)) 19 g3 = equidistant_grid(ll(3), lu(3), sz(3)...)
18 20
19 v1 = rand(sz(1)...) 21 v1 = rand(sz(1)...)
20 v2 = rand(sz(2)...) 22 v2 = rand(sz(2)...)
21 v3 = rand(sz(3)...) 23 v3 = rand(sz(3)...)
22 24
67 SUITE["derivatives"]["second_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3 69 SUITE["derivatives"]["second_derivative"]["3D"]["x"] = @benchmarkable $u3 .= $Dx*$v3
68 SUITE["derivatives"]["second_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3 70 SUITE["derivatives"]["second_derivative"]["3D"]["y"] = @benchmarkable $u3 .= $Dy*$v3
69 SUITE["derivatives"]["second_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3 71 SUITE["derivatives"]["second_derivative"]["3D"]["z"] = @benchmarkable $u3 .= $Dz*$v3
70 72
71 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
72 98
73 SUITE["derivatives"]["addition"] = BenchmarkGroup() 99 SUITE["derivatives"]["addition"] = BenchmarkGroup()
74 100
75 D₁ = first_derivative(g1,stencil_set) 101 D₁ = first_derivative(g1,stencil_set)
76 D₂ = second_derivative(g1,stencil_set) 102 D₂ = second_derivative(g1,stencil_set)
139 H = inner_product(g2, stencil_set) 165 H = inner_product(g2, stencil_set)
140 H⁻¹ = inverse_inner_product(g2, stencil_set) 166 H⁻¹ = inverse_inner_product(g2, stencil_set)
141 Dxx = second_derivative(g2, stencil_set, 1) 167 Dxx = second_derivative(g2, stencil_set, 1)
142 Dyy = second_derivative(g2, stencil_set, 2) 168 Dyy = second_derivative(g2, stencil_set, 2)
143 169
144 e₁ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,Lower}()) 170 e₁ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,LowerBoundary}())
145 e₁ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,Upper}()) 171 e₁ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{1,UpperBoundary}())
146 e₂ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,Lower}()) 172 e₂ₗ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,LowerBoundary}())
147 e₂ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,Upper}()) 173 e₂ᵤ = boundary_restriction(g2, stencil_set, CartesianBoundary{2,UpperBoundary}())
148 174
149 d₁ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{1,Lower}()) 175 d₁ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{1,LowerBoundary}())
150 d₁ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{1,Upper}()) 176 d₁ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{1,UpperBoundary}())
151 d₂ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{2,Lower}()) 177 d₂ₗ = normal_derivative(g2, stencil_set, CartesianBoundary{2,LowerBoundary}())
152 d₂ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{2,Upper}()) 178 d₂ᵤ = normal_derivative(g2, stencil_set, CartesianBoundary{2,UpperBoundary}())
153 179
154 H₁ₗ = inner_product(boundary_grid(g2, CartesianBoundary{1,Lower}()), stencil_set) 180 H₁ₗ = inner_product(boundary_grid(g2, CartesianBoundary{1,LowerBoundary}()), stencil_set)
155 H₁ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{1,Upper}()), stencil_set) 181 H₁ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{1,UpperBoundary}()), stencil_set)
156 H₂ₗ = inner_product(boundary_grid(g2, CartesianBoundary{2,Lower}()), stencil_set) 182 H₂ₗ = inner_product(boundary_grid(g2, CartesianBoundary{2,LowerBoundary}()), stencil_set)
157 H₂ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{2,Upper}()), stencil_set) 183 H₂ᵤ = inner_product(boundary_grid(g2, CartesianBoundary{2,UpperBoundary}()), stencil_set)
158 184
159 SUITE["boundary_terms"]["pre_composition"] = @benchmarkable $u2 .= $(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ)*$v2 185 SUITE["boundary_terms"]["pre_composition"] = @benchmarkable $u2 .= $(H⁻¹∘e₁ₗ'∘H₁ₗ∘d₁ₗ)*$v2
160 SUITE["boundary_terms"]["composition"] = @benchmarkable $u2 .= ($H⁻¹∘$e₁ₗ'∘$H₁ₗ∘$d₁ₗ)*$v2 186 SUITE["boundary_terms"]["composition"] = @benchmarkable $u2 .= ($H⁻¹∘$e₁ₗ'∘$H₁ₗ∘$d₁ₗ)*$v2
161 SUITE["boundary_terms"]["application"] = @benchmarkable $u2 .= $H⁻¹*$e₁ₗ'*$H₁ₗ* $d₁ₗ*$v2 187 SUITE["boundary_terms"]["application"] = @benchmarkable $u2 .= $H⁻¹*$e₁ₗ'*$H₁ₗ* $d₁ₗ*$v2
162 # An investigation of these allocations can be found in the branch `allocation_test` 188 # An investigation of these allocations can be found in the branch `allocation_test`