Benchmarking and site #3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Hyperfine | |
on: | |
push: | |
tags: | |
- 'v*' | |
workflow_dispatch: # This allows manual triggering | |
jobs: | |
benchmark: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 # Fetch all history for all branches and tags | |
- name: Clean previous docs folder | |
run: | | |
rm -rf docs/src/hyperfine.md | |
# rm -rf docs/src/criterion.md | |
- name: Set up Rust | |
uses: dtolnay/rust-toolchain@stable | |
- name: Build Release | |
run: cargo build --release | |
- name: Install hyperfine | |
run: sudo apt-get install hyperfine | |
- name: Run hyperfine benchmark | |
run: | | |
mkdir -p docs/src | |
echo "| File | Line num | Mean [ms] | Min [ms] | Max [ms] |" > docs/src/hyperfine.md | |
echo "|------|----------|-----------|----------|----------|" >> docs/src/hyperfine.md | |
for file in $(ls -S samples); do | |
file_name=$(basename "$file" .cls) | |
file_path="samples/$file" | |
line_count=$(wc -l < "$file_path") | |
file_url="https://github.com/${{ github.repository }}/blob/main/samples/$file" | |
file_link="[$file_name]($file_url)" | |
hyperfine --runs 100 --warmup 5 -i "./target/release/afmt -f $file_path" --export-markdown temp_results.md | |
mean=$(grep -oP '(?<=\| )[0-9.]+(?= ±)' temp_results.md | head -1) | |
min=$(grep -oP '(?<=\| )[0-9.]+(?= )' temp_results.md | head -2 | tail -1) | |
max=$(grep -oP '(?<=\| )[0-9.]+(?= )' temp_results.md | head -3 | tail -1) | |
if [ -n "$mean" ]; then | |
echo "| $file_link | $line_count | $mean | $min | $max |" >> docs/src/hyperfine.md | |
else | |
echo "| $file_link | $line_count | N/A | N/A | N/A |" >> docs/src/hyperfine.md | |
fi | |
done | |
- name: Install mdBook | |
run: cargo install mdbook | |
- name: Build mdBook | |
run: | | |
cd docs | |
mdbook build | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v3 | |
with: | |
path: ./docs/book | |
- name: Commit and Push Changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
git add docs | |
git commit -m "Update benchmark results and build mdBook" || echo "No changes to commit" | |
git push origin HEAD:main | |
deploy: | |
needs: benchmark | |
runs-on: ubuntu-latest | |
permissions: | |
pages: write | |
id-token: write | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
steps: | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v4 | |