Skip to content

Commit

Permalink
Print bench outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelburnham committed Oct 31, 2023
1 parent a976955 commit f7ab6d9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
25 changes: 16 additions & 9 deletions .github/workflows/merge-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')
44 changes: 24 additions & 20 deletions benches/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> {
Expand Down

0 comments on commit f7ab6d9

Please sign in to comment.