From f7ab6d9fe38da1e2e0a893b623a151b58a1f4caf Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:19:11 -0400 Subject: [PATCH] Print bench outputs --- .github/workflows/merge-tests.yml | 25 +++++++++++------- benches/fibonacci.rs | 44 +++++++++++++++++-------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/.github/workflows/merge-tests.yml b/.github/workflows/merge-tests.yml index db04a68d..cf7021d8 100644 --- a/.github/workflows/merge-tests.yml +++ b/.github/workflows/merge-tests.yml @@ -14,7 +14,7 @@ concurrency: jobs: gpu-benchmark: # Test working run - if: github.event_name != 'pull_request' || github.event.action == 'enqueued' + #if: github.event_name != 'pull_request' || github.event.action == 'enqueued' name: Run fibonacci bench runs-on: ubuntu-latest steps: @@ -42,26 +42,33 @@ jobs: - run: echo ${{ env.BASE_REF }} - name: Run bench on base branch run: cd main/benches && just --dotenv-filename bench.env bench fibonacci - - name: Copy bench output to PR branch - run: ls -a && cp main/${{ env.BASE_REF }}.json . + - name: Copy bench output to PR branch for comparison + #cp main/${{ env.BASE_REF }}.json . + run: | + cp -r main/target/criterion ./target + #- name: Print base bench + # run: cat ${{ env.BASE_REF }}.json - name: Run bench on PR branch - run: ls -a && cd benches && just --dotenv-filename bench.env bench fibonacci + run: cd benches && just --dotenv-filename bench.env bench fibonacci + - name: Print PR bench + run: cat ${{ github.sha }}.json # Create a `criterion-table` and write in commit comment - name: Run `criterion-table` run: cat ${{ github.sha }}.json | criterion-table > BENCHMARKS.md - - name: Write bench on commit comment - uses: peter-evans/commit-comment@v3 - with: - body-path: BENCHMARKS.md + #- name: Write bench on commit comment + # uses: peter-evans/commit-comment@v3 + # with: + # body-path: BENCHMARKS.md # TODO: Use jq for JSON parsing if needed # Check for benchmark regression based on Criterion's configured noise threshold - name: Performance regression check id: check-regression run: | + echo $(grep -c 'Regressed' ${{ github.sha }}.json) echo "regress_count=$(grep -c 'Regressed' ${{ github.sha }}.json)" >> $GITHUB_OUTPUT # Fail job if regression found - uses: actions/github-script@v6 - if: ${{ steps.check-regression.outputs.regress_count }} > 0 + if: ${{ steps.check-regression.outputs.regress_count > 0 }} with: script: | core.setFailed('Fibonacci bench regression detected') \ No newline at end of file diff --git a/benches/fibonacci.rs b/benches/fibonacci.rs index 7414ca15..5b229fd3 100644 --- a/benches/fibonacci.rs +++ b/benches/fibonacci.rs @@ -3,30 +3,34 @@ use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criteri #[inline] fn fib_recur(n: u64) -> u64 { - match n { - 0 => 1, - 1 => 1, - n => fib_recur(n - 1) + fib_recur(n - 2), - } + //match n { + // 0 => 1, + // 1 => 1, + // n => fib_recur(n - 1) + fib_recur(n - 2), + //} + std::thread::sleep(std::time::Duration::from_millis(1)); + 1 } #[inline] pub fn fib_iter(n: u64) -> u64 { - if n == 1 { - 1 - } else { - let mut sum = 0; - let mut last = 0; - let mut curr = 1; - - for _ in 1..n { - sum = last + curr; - last = curr; - curr = sum; - } - - sum - } + //if n == 1 { + // 1 + // } else { + // let mut sum = 0; + // let mut last = 0; + // let mut curr = 1; + + // for _ in 1..n { + // sum = last + curr; + // last = curr; + // curr = sum; + // } + + // sum + // } + std::thread::sleep(std::time::Duration::from_millis(1)); + 1 } fn noise_threshold_env() -> anyhow::Result {