Skip to content

Commit 8938720

Browse files
Implement benchmarking with AirspeedVelocity.jl (#119)
* Setup basic benchmarking * Simplify * Simplify * Add LinearAlgebra dep * Simplify scope structure for debugging * Add CI Action * Reorganize * Use product of test settings to construct individual tests * Formatting changes * Remove explicit LinearAlgebra ref * Combine multiple geometries into same loop * Bugfix * Add N field for evals settings * Add differentials tests * Tidying * Formatting fix * Update .github/workflows/AirspeedVelocity.yml * Update .github/workflows/AirspeedVelocity.yml * Update .github/workflows/AirspeedVelocity.yml * Use new versions of dependencies * Update .github/workflows/AirspeedVelocity.yml * Try to use benchmark script from head branch * Replace deprecated `::set-output` * Apply suggestions from code review Co-authored-by: Joshua Lampert <[email protected]> * Drop Unitful * Split indices --------- Co-authored-by: Joshua Lampert <[email protected]>
1 parent 6c8cd1f commit 8938720

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Benchmark a Pull Request
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
permissions:
9+
pull-requests: write
10+
11+
jobs:
12+
benchmark:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: julia-actions/setup-julia@v2
18+
with:
19+
version: "1.10"
20+
- uses: julia-actions/cache@v2
21+
- name: Extract Package Name from Project.toml
22+
id: extract-package-name
23+
run: |
24+
PACKAGE_NAME=$(grep "^name" Project.toml | sed 's/^name = "\(.*\)"$/\1/')
25+
echo "package_name=$PACKAGE_NAME" >> $GITHUB_OUTPUT
26+
- name: Build AirspeedVelocity
27+
env:
28+
JULIA_NUM_THREADS: 2
29+
run: |
30+
# Lightweight build step, as sometimes the runner runs out of memory:
31+
julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.add(;url="https://github.com/MilesCranmer/AirspeedVelocity.jl.git")'
32+
julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.build("AirspeedVelocity")'
33+
- name: Add ~/.julia/bin to PATH
34+
run: |
35+
echo "$HOME/.julia/bin" >> $GITHUB_PATH
36+
- name: Run benchmarks
37+
run: |
38+
echo $PATH
39+
ls -l ~/.julia/bin
40+
mkdir results
41+
benchpkg ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --url=${{ github.event.repository.clone_url }} --bench-on="${{github.event.pull_request.head.sha}}" --output-dir=results/ --tune
42+
- name: Create plots from benchmarks
43+
run: |
44+
mkdir -p plots
45+
benchpkgplot ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --npart=10 --format=png --input-dir=results/ --output-dir=plots/
46+
- name: Upload plot as artifact
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: plots
50+
path: plots
51+
- name: Create markdown table from benchmarks
52+
run: |
53+
benchpkgtable ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --input-dir=results/ --ratio > table.md
54+
echo '### Benchmark Results' > body.md
55+
echo '' >> body.md
56+
echo '' >> body.md
57+
cat table.md >> body.md
58+
echo '' >> body.md
59+
echo '' >> body.md
60+
echo '### Benchmark Plots' >> body.md
61+
echo 'A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.' >> body.md
62+
echo 'Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).' >> body.md
63+
64+
- name: Find Comment
65+
uses: peter-evans/find-comment@v3
66+
id: fcbenchmark
67+
with:
68+
issue-number: ${{ github.event.pull_request.number }}
69+
comment-author: 'github-actions[bot]'
70+
body-includes: Benchmark Results
71+
72+
- name: Comment on PR
73+
uses: peter-evans/create-or-update-comment@v4
74+
with:
75+
comment-id: ${{ steps.fcbenchmark.outputs.comment-id }}
76+
issue-number: ${{ github.event.pull_request.number }}
77+
body-path: body.md
78+
edit-mode: replace

benchmark/Project.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
4+
Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
5+
6+
[compat]
7+
BenchmarkTools = "1.5"
8+
LinearAlgebra = "1"
9+
Meshes = "0.50, 0.51, 0.52"

benchmark/benchmarks.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using BenchmarkTools
2+
using LinearAlgebra
3+
using Meshes
4+
using MeshIntegrals
5+
6+
const SUITE = BenchmarkGroup()
7+
8+
############################################################################################
9+
# Integrals
10+
############################################################################################
11+
12+
integrands = (
13+
(name = "Scalar", f = p -> norm(to(p))),
14+
(name = "Vector", f = p -> fill(norm(to(p)), 3))
15+
)
16+
rules = (
17+
(name = "GaussLegendre", rule = GaussLegendre(100), N = 100),
18+
(name = "GaussKronrod", rule = GaussKronrod(), N = 100),
19+
(name = "HAdaptiveCubature", rule = HAdaptiveCubature(), N = 500)
20+
)
21+
geometries = (
22+
(name = "Meshes.Segment", item = Segment(Point(0, 0, 0), Point(1, 1, 1))),
23+
(name = "Meshes.Sphere", item = Sphere(Point(0, 0, 0), 1.0))
24+
)
25+
26+
SUITE["Integrals"] = let s = BenchmarkGroup()
27+
for (int, rule, geometry) in Iterators.product(integrands, rules, geometries)
28+
n1, n2, N = geometry.name, "$(int.name) $(rule.name)", rule.N
29+
s[n1][n2] = @benchmarkable integral($int.f, $geometry.item, $rule.rule) evals=N
30+
end
31+
s
32+
end
33+
34+
############################################################################################
35+
# Differentials
36+
############################################################################################
37+
38+
sphere = geometries[2].item
39+
differential = MeshIntegrals.differential
40+
41+
SUITE["Differentials"] = let s = BenchmarkGroup()
42+
s["Jacobian"] = @benchmarkable jacobian($sphere, $(0.5, 0.5)) evals=1000
43+
s["Differential"] = @benchmarkable differential($sphere, $(0.5, 0.5)) evals=1000
44+
s
45+
end
46+
47+
#tune!(SUITE)
48+
#run(SUITE, verbose=true)

0 commit comments

Comments
 (0)