From 67ce672c9ae329469e429b31f7e9411a303fb29d Mon Sep 17 00:00:00 2001 From: Zentrik Date: Sun, 9 Apr 2023 16:05:13 +0100 Subject: [PATCH] Add benchmarks and CI using AirspeedVelocity --- .github/workflows/benchmark_pr.yml | 68 ++++++++++++++++++++++++++++++ benchmark/benchmarks.jl | 32 ++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 .github/workflows/benchmark_pr.yml create mode 100644 benchmark/benchmarks.jl diff --git a/.github/workflows/benchmark_pr.yml b/.github/workflows/benchmark_pr.yml new file mode 100644 index 0000000..c67ff0e --- /dev/null +++ b/.github/workflows/benchmark_pr.yml @@ -0,0 +1,68 @@ +name: Benchmark a pull request + +on: + pull_request_target: + branches: + - master + +permissions: + pull-requests: write + +jobs: + generate_plots: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: "1.8" + - uses: julia-actions/cache@v1 + - name: Extract Package Name from Project.toml + id: extract-package-name + run: | + PACKAGE_NAME=$(grep "^name" Project.toml | sed 's/^name = "\(.*\)"$/\1/') + echo "::set-output name=package_name::$PACKAGE_NAME" + - name: Build AirspeedVelocity + env: + JULIA_NUM_THREADS: 2 + run: | + # Lightweight build step, as sometimes the runner runs out of memory: + julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.add(;url="https://github.com/MilesCranmer/AirspeedVelocity.jl.git")' + julia -e 'ENV["JULIA_PKG_PRECOMPILE_AUTO"]=0; import Pkg; Pkg.build("AirspeedVelocity")' + - name: Add ~/.julia/bin to PATH + run: | + echo "$HOME/.julia/bin" >> $GITHUB_PATH + - name: Run benchmarks + run: | + echo $PATH + ls -l ~/.julia/bin + mkdir results + 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.repository.default_branch}}" --output-dir=results/ + - name: Create plots from benchmarks + run: | + mkdir -p plots + 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/ + - name: Upload plot as artifact + uses: actions/upload-artifact@v2 + with: + name: plots + path: plots + - name: Create markdown table from benchmarks + run: | + julia -e 'using AirspeedVelocity; combined_results=load_results("${{ steps.extract-package-name.outputs.package_name }}", ["${{github.event.repository.default_branch}}", "${{github.event.pull_request.head.sha}}"], input_dir="results"); table = create_table(combined_results); open("table.md", "w") do io; print(io, table); end' + echo '### Benchmark Results' > body.md + echo '' >> body.md + echo '' >> body.md + cat table.md >> body.md + echo '' >> body.md + echo '' >> body.md + echo '### Benchmark Plots' >> body.md + echo 'A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.' >> body.md + echo 'Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).' >> body.md + + - name: Comment on PR + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ github.event.pull_request.number }} + body-path: body.md \ No newline at end of file diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl new file mode 100644 index 0000000..c71a672 --- /dev/null +++ b/benchmark/benchmarks.jl @@ -0,0 +1,32 @@ +using BenchmarkTools + +const SUITE = BenchmarkGroup() + +function perf_steprange_long(x, a) + s = zero(eltype(x)) + + @inbounds for j in a + for i in LoopVecRange{8}(1, j) + s += x[i] + end + end + + return s +end + +function perf_steprange(x) + s = zero(eltype(x)) + + @inbounds for i in LoopVecRange{8}(x) + s += x[i] + end + + return s +end + +SUITE["LoopVecRange"] = BenchmarkGroup(["string", "unicode"]) + +SUITE["LoopVecRange"]["steprange"] = @benchmarkable perf_steprange($x) setup=(x=rand(800)) + +tmp_x=rand(800) +SUITE["LoopVecRange"]["steprange_long"] = @benchmarkable perf_steprange_long($tmp_x, $(rand(round(Int, length(tmp_x) / 2):length(tmp_x), 10^6))) \ No newline at end of file