Skip to content

Commit aaad11b

Browse files
refactor: move the benchmark display helpers to the upload module
1 parent 7485037 commit aaad11b

5 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/cli/run/helpers/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub(crate) mod benchmark_display;
21
mod download_file;
32
mod find_repository_root;
43
mod format_duration;
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use tabled::settings::style::HorizontalLine;
1111
use tabled::settings::{Alignment, Color, Modify, Padding, Style};
1212
use tabled::{Table, Tabled};
1313

14+
/// Changes below this threshold are displayed as "~0%" to avoid noise.
15+
pub(super) const CHANGE_DISPLAY_EPSILON: f64 = 0.005;
16+
1417
fn format_with_thousands_sep(n: u64) -> String {
1518
let s = n.to_string();
1619
let mut result = String::new();
@@ -366,15 +369,15 @@ pub fn build_comparison_table(results: &[CompareRunsBenchmarkResult]) -> String
366369
};
367370

368371
let change_str = match result.change {
372+
Some(c) if c.abs() < CHANGE_DISPLAY_EPSILON => {
373+
format!("{}", style(format!("{:.1}%", c * 100.0)).dim())
374+
}
369375
Some(c) if c > 0.0 => {
370-
let pct = (c * 100.0).round();
371-
format!("{}", style(format!("+{pct}%")).red().bold())
376+
format!("{}", style(format!("+{:.1}%", c * 100.0)).green().bold())
372377
}
373-
Some(c) if c < 0.0 => {
374-
let pct = (c * 100.0).round();
375-
format!("{}", style(format!("{pct}%")).green().bold())
378+
Some(c) => {
379+
format!("{}", style(format!("{:.1}%", c * 100.0)).red().bold())
376380
}
377-
Some(_) => format!("{}", style("0%").dim()),
378381
None => "-".to_string(),
379382
};
380383

src/upload/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod benchmark_display;
12
mod interfaces;
23
pub mod poll_results;
34
mod profile_archive;

src/upload/poll_results.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ use std::time::Duration;
44
use console::style;
55
use tokio::time::{Instant, sleep};
66

7-
use crate::api_client::{
8-
CodSpeedAPIClient, CompareRunsResponse, CompareRunsVars, FetchLocalRunResponse,
9-
FetchLocalRunVars, RunStatus,
7+
use super::benchmark_display::{
8+
self, build_benchmark_table, build_comparison_table, build_detailed_summary,
109
};
11-
use crate::cli::run::helpers::benchmark_display::{
12-
build_benchmark_table, build_comparison_table, build_detailed_summary,
10+
use crate::api_client::{
11+
CodSpeedAPIClient, CompareRunsOutcome, CompareRunsResponse, CompareRunsVars,
12+
FetchLocalRunResponse, FetchLocalRunVars, RunStatus,
1313
};
1414
use crate::local_logger::{start_spinner, stop_spinner};
1515
use crate::prelude::*;

src/cli/run/helpers/snapshots/codspeed_runner__cli__run__helpers__benchmark_display__tests__benchmark_table_formatting.snap renamed to src/upload/snapshots/codspeed_runner__upload__benchmark_display__tests__benchmark_table_formatting.snap

File renamed without changes.

0 commit comments

Comments
 (0)