Skip to content

Commit

Permalink
fail ci on positive percentage change > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
alankritdabral authored and tusharmath committed Dec 19, 2023
1 parent b928f7a commit f4c3da7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions benches/criterion_compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,31 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let comparison_table_markdown = generate_comparison_table_markdown(&old_benchmarks, &new_benchmarks)?;
fs::write(markdown_output_file_path, comparison_table_markdown)?;

// Check for benchmarks exceeding the 1% change threshold
// Collect benchmarks exceeding the 1% change threshold
let benchmarks_exceeding_threshold: Vec<_> = old_benchmarks
.iter()
.zip(new_benchmarks.iter())
.filter_map(|(old, new)| {
let percentage_change = calculate_percentage_change(old.typical.estimate, new.typical.estimate);
if percentage_change.abs() > 1.0 {
if percentage_change > 1.0 {
Some(old.id.clone())
} else {
None
}
})
.collect();

// If there are benchmarks exceeding the threshold, print their names
// Print the benchmarks exceeding the threshold
if !benchmarks_exceeding_threshold.is_empty() {
let exceeding_benchmarks_str = benchmarks_exceeding_threshold.join(", ");
println!(
"Benchmarks exceeding the 1% change threshold: {}",
exceeding_benchmarks_str
);

// Fail the CI with a non-zero exit code
eprintln!("Error: Benchmarks exceeding the 1% change threshold");
std::process::exit(1);
}

Ok(())
Expand Down

0 comments on commit f4c3da7

Please sign in to comment.