Skip to content

Commit 2420f78

Browse files
committed
Add benchmark and AirspeedVelocity action
1 parent 9590a39 commit 2420f78

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.github/workflows/benchmark_pr.yml

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_target:
5+
branches:
6+
- master
7+
8+
permissions:
9+
pull-requests: write
10+
11+
jobs:
12+
generate_plots:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- uses: julia-actions/setup-julia@v1
18+
with:
19+
version: "1"
20+
- uses: julia-actions/cache@v1
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 "::set-output name=package_name::$PACKAGE_NAME"
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/ --exeflags="-O3 --threads=auto"
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@v2
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@v2
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@v3
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3+
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

benchmark/benchmarks.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using BenchmarkTools
2+
using DynamicUnits
3+
4+
const SUITE = BenchmarkGroup()
5+
6+
SUITE["creation"] = let s = BenchmarkGroup()
7+
s["Quantity(x)"] = @benchmarkable Quantity(x) setup = (x = randn()) evals = 1000
8+
s["Quantity(x, length=y)"] = @benchmarkable Quantity(x, length=y) setup = (x = randn(); y = rand(1:5)) evals = 1000
9+
s
10+
end
11+
12+
default() = Quantity(rand(), length=rand(1:5), mass=rand(1:5) // 2)
13+
14+
SUITE["with_numbers"] = let s = BenchmarkGroup()
15+
f1(x, i) = x^i
16+
s["^int"] = @benchmarkable $f1(x, i) setup = (x = default(); i = rand(1:5)) evals = 1000
17+
f2(x, y) = x * y
18+
s["*real"] = @benchmarkable $f2(x, y) setup = (x = default(); y = randn()) evals = 1000
19+
f3(x, i, y) = x^i * y
20+
s["^int * real"] = @benchmarkable $f3(x, i, y) setup = (x = default(); i = rand(1:5); y = randn()) evals = 1000
21+
s
22+
end
23+
24+
SUITE["with_self"] = let s = BenchmarkGroup()
25+
f4(x) = inv(x)
26+
s["inv"] = @benchmarkable $f4(x) setup = (x = default()) evals = 1000
27+
f7(x) = ustrip(x)
28+
s["ustrip"] = @benchmarkable $f7(x) setup = (x = default()) evals = 1000
29+
f8(x) = dimension(x)
30+
s["dimension"] = @benchmarkable $f8(x) setup = (x = default()) evals = 1000
31+
s
32+
end
33+
34+
SUITE["with_quantity"] = let s = BenchmarkGroup()
35+
f5(x, y) = x / y
36+
s["/y"] = @benchmarkable $f5(x, y) setup = (x = default(); y = default()) evals = 1000
37+
f6(x, y) = x^y
38+
s["^y"] = @benchmarkable $f6(x, y) setup = (x = default(); y = default() / dimension(default())) evals = 1000
39+
s
40+
end

0 commit comments

Comments
 (0)