Skip to content

Commit 53ef5f0

Browse files
committed
feat(bench): minor styling changes
1 parent 867e973 commit 53ef5f0

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

src/bin/bench_throughput.rs

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use clap::{Arg, Command};
2-
use comfy_table::{presets::UTF8_FULL, Attribute as TableAttribute, Cell, CellAlignment, Color as TableColor, ContentArrangement, Table};
2+
use comfy_table::{
3+
Attribute as TableAttribute, Cell, Color as TableColor, ContentArrangement, Table,
4+
presets::UTF8_FULL,
5+
};
36
use crossterm::{
47
cursor, execute, queue,
58
style::{Attribute, Color, Print, ResetColor, SetAttribute, SetForegroundColor},
@@ -271,18 +274,12 @@ impl TemplateSet {
271274
("Extract directory", "{split:/:0..-1|join:/}"),
272275
("Basename no ext", "{split:/:-1|split:.:0}"),
273276
("File extension", "{split:/:-1|split:.:-1}"),
274-
(
275-
"Regex extract filename",
276-
"{regex_extract:[^/]+$}",
277-
),
277+
("Regex extract filename", "{regex_extract:[^/]+$}"),
278278
(
279279
"Uppercase all components",
280280
"{split:/:..|map:{upper}|join:/}",
281281
),
282-
(
283-
"Remove hidden dirs",
284-
"{split:/:..|filter_not:^\\.|join:/}",
285-
),
282+
("Remove hidden dirs", "{split:/:..|filter_not:^\\.|join:/}"),
286283
("Normalize filename", "{split:/:-1|trim|lower}"),
287284
("Slug generation", "{replace:s/ /_/g|lower}"),
288285
("Breadcrumb last 3", "{split:/:..|slice:-3..|join: > }"),
@@ -397,14 +394,13 @@ fn print_header(text: &str) {
397394
let mut stdout = io::stdout();
398395
let _ = execute!(
399396
stdout,
400-
Print("\n"),
401397
SetForegroundColor(Color::Cyan),
402398
SetAttribute(Attribute::Bold),
403399
Print("╔"),
404400
Print("═".repeat(108)),
405401
Print("╗\n║ "),
406402
Print(text),
407-
Print(" ".repeat(106 - text.len())),
403+
Print(" ".repeat(110 - text.len())),
408404
Print("║\n╚"),
409405
Print("═".repeat(108)),
410406
Print("╝\n"),
@@ -424,7 +420,6 @@ fn print_section_header(text: &str) {
424420
Print("\n"),
425421
SetForegroundColor(Color::DarkGrey),
426422
Print("─".repeat(110)),
427-
Print("\n"),
428423
ResetColor
429424
);
430425
}
@@ -487,13 +482,27 @@ fn print_template_results(template_name: &str, results: &[BenchmarkResult], deta
487482
.load_preset(UTF8_FULL)
488483
.set_content_arrangement(ContentArrangement::Dynamic)
489484
.set_header(vec![
490-
Cell::new("Input Size").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
491-
Cell::new("Parse Time").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
492-
Cell::new("Total Time").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
493-
Cell::new("Avg/Path").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
494-
Cell::new("Throughput").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
495-
Cell::new("Parse %").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
496-
Cell::new("Scaling").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
485+
Cell::new("Input Size")
486+
.add_attribute(TableAttribute::Bold)
487+
.fg(TableColor::Yellow),
488+
Cell::new("Parse Time")
489+
.add_attribute(TableAttribute::Bold)
490+
.fg(TableColor::Yellow),
491+
Cell::new("Total Time")
492+
.add_attribute(TableAttribute::Bold)
493+
.fg(TableColor::Yellow),
494+
Cell::new("Avg/Path")
495+
.add_attribute(TableAttribute::Bold)
496+
.fg(TableColor::Yellow),
497+
Cell::new("Throughput")
498+
.add_attribute(TableAttribute::Bold)
499+
.fg(TableColor::Yellow),
500+
Cell::new("Parse %")
501+
.add_attribute(TableAttribute::Bold)
502+
.fg(TableColor::Yellow),
503+
Cell::new("Scaling")
504+
.add_attribute(TableAttribute::Bold)
505+
.fg(TableColor::Yellow),
497506
]);
498507

499508
for (idx, result) in results.iter().enumerate() {
@@ -573,7 +582,10 @@ fn print_template_results(template_name: &str, results: &[BenchmarkResult], deta
573582

574583
// Latency statistics
575584
let stats = &largest_result.latency_stats;
576-
println!("\n📈 Latency Statistics (at {} inputs):", format_size(largest_result.input_size));
585+
println!(
586+
"\n📈 Latency Statistics (at {} inputs):",
587+
format_size(largest_result.input_size)
588+
);
577589
println!(
578590
" Min: {} p50: {} p95: {} p99: {} Max: {} Stddev: {:.2}ns",
579591
format_duration(stats.min),
@@ -583,6 +595,7 @@ fn print_template_results(template_name: &str, results: &[BenchmarkResult], deta
583595
format_duration(stats.max),
584596
stats.stddev
585597
);
598+
println!();
586599
}
587600
}
588601

@@ -613,13 +626,22 @@ fn print_summary(all_results: &[(&str, Vec<BenchmarkResult>)]) {
613626
.load_preset(UTF8_FULL)
614627
.set_content_arrangement(ContentArrangement::Dynamic)
615628
.set_header(vec![
616-
Cell::new("Template").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
617-
Cell::new("Input Size").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
618-
Cell::new("Avg/Path").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
619-
Cell::new("Throughput").add_attribute(TableAttribute::Bold).fg(TableColor::Yellow),
629+
Cell::new("Template")
630+
.add_attribute(TableAttribute::Bold)
631+
.fg(TableColor::Yellow),
632+
Cell::new("Input Size")
633+
.add_attribute(TableAttribute::Bold)
634+
.fg(TableColor::Yellow),
635+
Cell::new("Avg/Path")
636+
.add_attribute(TableAttribute::Bold)
637+
.fg(TableColor::Yellow),
638+
Cell::new("Throughput")
639+
.add_attribute(TableAttribute::Bold)
640+
.fg(TableColor::Yellow),
620641
]);
621642

622-
for (idx, (template_name, input_size, avg_time, throughput)) in summary_data.iter().enumerate() {
643+
for (idx, (template_name, input_size, avg_time, throughput)) in summary_data.iter().enumerate()
644+
{
623645
// Highlight fastest (green) and slowest (yellow)
624646
let color = if idx == 0 {
625647
TableColor::Green
@@ -637,15 +659,7 @@ fn print_summary(all_results: &[(&str, Vec<BenchmarkResult>)]) {
637659
]);
638660
}
639661

640-
println!("\n{}", table);
641-
}
642-
643-
fn truncate_name(name: &str, max_len: usize) -> String {
644-
if name.len() <= max_len {
645-
name.to_string()
646-
} else {
647-
format!("{}...", &name[..max_len - 3])
648-
}
662+
println!("{}", table);
649663
}
650664

651665
/// Output results in JSON format for tracking over time
@@ -790,7 +804,10 @@ fn main() {
790804
SetForegroundColor(Color::Cyan),
791805
Print("Input sizes: "),
792806
ResetColor,
793-
Print(format!("{:?}\n", sizes.iter().map(|s| format_size(*s)).collect::<Vec<_>>())),
807+
Print(format!(
808+
"{:?}\n",
809+
sizes.iter().map(|s| format_size(*s)).collect::<Vec<_>>()
810+
)),
794811
SetForegroundColor(Color::Cyan),
795812
Print("Measurement iterations: "),
796813
ResetColor,
@@ -852,18 +869,17 @@ fn main() {
852869
print_summary(&all_results);
853870
}
854871

855-
if format == "json" {
856-
if let Err(e) = output_json(&all_results, output_path.map(|s| s.as_str())) {
857-
eprintln!("Error writing JSON output: {}", e);
858-
std::process::exit(1);
859-
}
872+
if format == "json"
873+
&& let Err(e) = output_json(&all_results, output_path.map(|s| s.as_str()))
874+
{
875+
eprintln!("Error writing JSON output: {}", e);
876+
std::process::exit(1);
860877
}
861878

862879
if !quiet {
863880
let mut stdout = io::stdout();
864881
let _ = execute!(
865882
stdout,
866-
Print("\n"),
867883
SetForegroundColor(Color::Green),
868884
SetAttribute(Attribute::Bold),
869885
Print("✓ Benchmark complete!\n"),

0 commit comments

Comments
 (0)