Skip to content

Commit

Permalink
ci: also run benchmarks as tests
Browse files Browse the repository at this point in the history
For `nextest`'s parsing of `cargo criterion --list --format terse` to
work, benchmarks must not print to standard out.
  • Loading branch information
jan-ferdinand committed Mar 7, 2024
1 parent 718b211 commit 05c139f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ jobs:
run: cargo run --bin constraint-evaluation-generator

- name: Collect coverage data
run: cargo llvm-cov nextest --lcov --output-path lcov.info --features integration-tests
run: >
cargo llvm-cov nextest
--all-targets
--features integration-tests
--lcov --output-path lcov.info
- name: Upload coverage to coveralls.io
uses: coverallsapp/github-action@v2
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ jobs:
run: cargo clippy --all-targets -- -D warnings

- name: Run tests
run: cargo nextest run --no-fail-fast --tests

- name: Run examples
run: cargo nextest run --no-fail-fast --examples
run: cargo nextest run --no-fail-fast --all-targets

# doctests are special [^1] but this step does not incur a performance penalty [^2]
#
Expand Down
12 changes: 6 additions & 6 deletions triton-vm/benches/proof_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,18 @@ fn print_proof_size_breakdown(program_name: &str, proof: &Proof) {
let proof_size_breakdown = break_down_proof_size(proof);
let proof_size_breakdown = sort_hash_map_by_value_descending(proof_size_breakdown);

println!();
println!("Proof size breakdown for {program_name}:");
println!(
eprintln!();
eprintln!("Proof size breakdown for {program_name}:");
eprintln!(
"| {:<30} | {:>10} | {:>6} |",
"Category", "Size [bfe]", "[%]"
);
println!("|:{:-<30}-|-{:->10}:|-{:->6}:|", "", "", "");
eprintln!("|:{:-<30}-|-{:->10}:|-{:->6}:|", "", "", "");
for (category, size) in proof_size_breakdown {
let relative_size = (size as f64) / (total_proof_size as f64) * 100.0;
println!("| {category:<30} | {size:>10} | {relative_size:>6.2} |");
eprintln!("| {category:<30} | {size:>10} | {relative_size:>6.2} |");
}
println!();
eprintln!();
}

/// Create `num_iterations` many proofs for the program with the supplied source code and
Expand Down
3 changes: 1 addition & 2 deletions triton-vm/benches/prove_fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ fn prove_fib(criterion: &mut Criterion) {
fib_benchmark_group(criterion, &claim, &aet);

let report = prover_timing_report(&claim, &aet);
println!("Writing report ...");
println!("{report}");
eprintln!("{report}");
}

fn fib_benchmark_group(criterion: &mut Criterion, claim: &Claim, aet: &AlgebraicExecutionTrace) {
Expand Down
3 changes: 1 addition & 2 deletions triton-vm/benches/prove_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ fn prove_halt(criterion: &mut Criterion) {
});
group.finish();

println!("Writing report ...");
let padded_height = proof.padded_height().unwrap();
let fri = stark.derive_fri(padded_height).unwrap();
let report = profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length);
println!("{report}");
eprintln!("{report}");
}

criterion_group! {
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/benches/verify_halt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn verify_halt(criterion: &mut Criterion) {
});
group.finish();

println!("{report}");
eprintln!("{report}");
}

criterion_group! {
Expand Down
26 changes: 13 additions & 13 deletions triton-vm/src/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,6 @@ impl TritonProfiler {
);

let mut report: Vec<TaskReport> = vec![];
let total_tracked_time = (self.total_time.as_nanos()
- self
.profile
.iter()
.filter(|t| t.task_type == TaskType::AnyOtherIteration)
.map(|t| t.time.as_nanos())
.sum::<u128>()) as f64
/ 1_000_000_000f64;
println!(
"total time: {}s and tracked: {}s",
self.total_time.as_secs_f64(),
total_tracked_time,
);

// collect all categories and their total times
// todo: this can count the same category multiple times if it's nested
Expand Down Expand Up @@ -189,6 +176,7 @@ impl TritonProfiler {
tasks: report,
name: self.name.clone(),
total_time: self.total_time,
tracked_time: self.tracked_time(),
category_times,
cycle_count: None,
padded_height: None,
Expand Down Expand Up @@ -310,6 +298,14 @@ impl TritonProfiler {
self.plain_stop();
}
}

pub fn tracked_time(&self) -> Duration {
let is_other_iteration = |t: &&Task| t.task_type == TaskType::AnyOtherIteration;
let all_tasks = self.profile.iter();
let other_iterations = all_tasks.filter(is_other_iteration);
let untracked_time = other_iterations.map(|t| t.time).sum();
self.total_time.saturating_sub(untracked_time)
}
}

impl Profiler for TritonProfiler {
Expand Down Expand Up @@ -391,6 +387,7 @@ pub struct Report {
name: String,
tasks: Vec<TaskReport>,
total_time: Duration,
tracked_time: Duration,
category_times: HashMap<String, Duration>,
cycle_count: Option<usize>,
padded_height: Option<usize>,
Expand Down Expand Up @@ -444,6 +441,9 @@ impl Display for Report {
let title = format!("{title:<max_width$}");

let total_time_string = Report::display_time_aligned(self.total_time).bold();
let tracked_time = Report::display_time_aligned(self.tracked_time);
writeln!(f, "tracked time: {tracked_time}s")?;

let share_string = "Share".to_string().bold();
let category_string = match self.category_times.is_empty() {
true => ColoredString::default(),
Expand Down

0 comments on commit 05c139f

Please sign in to comment.