MCPcopy Create free account
hub / github.com/CodSpeedHQ/codspeed / build_comparison_table

Function build_comparison_table

src/upload/benchmark_display.rs:348–428  ·  view source on GitHub ↗
(results: &[CompareRunsBenchmarkResult])

Source from the content-addressed store, hash-verified

346}
347
348pub fn build_comparison_table(results: &[CompareRunsBenchmarkResult]) -> String {
349 let mut grouped: HashMap<&ExecutorName, Vec<&CompareRunsBenchmarkResult>> = HashMap::new();
350 for result in results {
351 grouped
352 .entry(&result.benchmark.executor)
353 .or_default()
354 .push(result);
355 }
356
357 let executor_order = [
358 ExecutorName::Valgrind,
359 ExecutorName::WallTime,
360 ExecutorName::Memory,
361 ];
362
363 let mut output = String::new();
364 for executor in &executor_order {
365 if let Some(executor_results) = grouped.get(executor) {
366 if !output.is_empty() {
367 output.push('\n');
368 }
369 let rows: Vec<ComparisonRow> = executor_results
370 .iter()
371 .map(|result| {
372 let format_value = |v: Option<f64>| match v {
373 Some(v) => match executor {
374 ExecutorName::Memory => helpers::format_memory(v, Some(1)),
375 _ => helpers::format_duration(v, Some(2)),
376 },
377 None => "-".to_string(),
378 };
379
380 let change_str = match result.change {
381 Some(c) if c.abs() < CHANGE_DISPLAY_EPSILON => {
382 format!("{}", style(format!("{:.1}%", c * 100.0)).dim())
383 }
384 Some(c) if c > 0.0 => {
385 format!("{}", style(format!("+{:.1}%", c * 100.0)).green().bold())
386 }
387 Some(c) => {
388 format!("{}", style(format!("{:.1}%", c * 100.0)).red().bold())
389 }
390 None => "-".to_string(),
391 };
392
393 let status_str = match &result.category {
394 ResultComparisonCategory::New => {
395 format!("{}", style("New").cyan().bold())
396 }
397 ResultComparisonCategory::Improvement => {
398 format!("{}", style("Improvement").green().bold())
399 }
400 ResultComparisonCategory::Regression => {
401 format!("{}", style("Regression").red().bold())
402 }
403 ResultComparisonCategory::Untouched => {
404 format!("{}", style("No Change").dim())
405 }

Callers 1

Calls 6

format_memoryFunction · 0.85
format_durationFunction · 0.85
build_table_with_styleFunction · 0.85
labelMethod · 0.80
iconMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected