Improve benchmark outputs
adbce514260289f7ba10d505f89fd3709ee2bbec
1 parent
b005b61f
crates/diff/benches/render.rs
+13 -28
| 9 | 9 | use std::time::{Duration, Instant}; |
|
| 10 | 10 | ||
| 11 | 11 | use rustik_diff::{ |
|
| 12 | 12 | Decode, DiffAction, DiffDocument, DiffOptions, DiffViewer, HighlightRequest, HighlightResult, |
|
| 13 | 13 | }; |
|
| 14 | - | use rustik_tui::{Buffer, Color, Constraint, Label, Line, Rect, Scroll, Table, TableOptions}; |
|
| 14 | + | use rustik_tui::{ |
|
| 15 | + | Buffer, Color, Constraint, Label, Line, Rect, Scroll, Style, Table, TableOptions, |
|
| 16 | + | }; |
|
| 15 | 17 | ||
| 16 | - | /// Human-readable workload name printed by the benchmark report. |
|
| 17 | - | const WORKLOAD: &str = "rustik-diff-render"; |
|
| 18 | 18 | /// Fixed terminal-sized render area. |
|
| 19 | 19 | const AREA: Rect = Rect::new(0, 0, 120, 40); |
|
| 20 | 20 | /// Narrow terminal area used by resize-heavy scenarios. |
|
| 21 | 21 | const NARROW_AREA: Rect = Rect::new(0, 0, 80, 24); |
|
| 22 | 22 | /// Wide terminal area used by resize-heavy scenarios. |
| 35 | 35 | const DEFAULT_LINES: usize = 128; |
|
| 36 | 36 | /// One row sample stride for the checksum. |
|
| 37 | 37 | const SAMPLE_ROWS: usize = 5; |
|
| 38 | 38 | /// One column sample stride for the checksum. |
|
| 39 | 39 | const SAMPLE_COLS: usize = 7; |
|
| 40 | + | /// Low-emphasis report text color. |
|
| 41 | + | const REPORT_DIM: Color = Color::Fixed(244); |
|
| 40 | 42 | ||
| 41 | 43 | /// Runs the benchmark. |
|
| 42 | 44 | fn main() { |
|
| 43 | 45 | let args = Args::parse(); |
|
| 44 | - | println!("{WORKLOAD} {}", args.workload.name()); |
|
| 45 | - | flush_stdout(); |
|
| 46 | 46 | let workloads = args.workload.expanded(); |
|
| 47 | 47 | let report_widths = ReportWidths::new(&workloads); |
|
| 48 | - | let mut header = HeaderMode::Show; |
|
| 49 | - | let reports = workloads |
|
| 50 | - | .into_iter() |
|
| 51 | - | .map(|workload| { |
|
| 52 | - | let report = run_workload(workload, args); |
|
| 53 | - | report_workload(&report, report_widths, header); |
|
| 54 | - | header = HeaderMode::Hide; |
|
| 55 | - | report |
|
| 56 | - | }) |
|
| 57 | - | .collect::<Vec<_>>(); |
|
| 58 | - | let checksum = reports.iter().fold(0usize, |value, report| { |
|
| 59 | - | value ^ report.checksum.rotate_left(report.workload as u32) |
|
| 60 | - | }); |
|
| 48 | + | let mut checksum = 0usize; |
|
| 61 | 49 | ||
| 50 | + | for workload in workloads { |
|
| 51 | + | let report = run_workload(workload, args); |
|
| 52 | + | checksum ^= report.checksum.rotate_left(report.workload as u32); |
|
| 53 | + | report_workload(&report, report_widths); |
|
| 54 | + | black_box(report); |
|
| 55 | + | } |
|
| 62 | 56 | black_box(checksum); |
|
| 63 | - | black_box(reports); |
|
| 64 | 57 | } |
|
| 65 | 58 | ||
| 66 | 59 | /// Benchmark command-line arguments. |
|
| 67 | 60 | #[derive(Clone, Copy, Debug)] |
|
| 68 | 61 | struct Args { |
| 337 | 330 | workload: usize, |
|
| 338 | 331 | /// Width reserved for formatted workload rates. |
|
| 339 | 332 | rate: usize, |
|
| 340 | 333 | } |
|
| 341 | 334 | ||
| 335 | + | /// Widest expected workload-rate value used to keep streaming rows aligned. |
|
| 342 | 336 | const RATE_FORMAT: &str = "000000.0"; |
|
| 343 | 337 | ||
| 344 | - | /// Whether a streaming row should include the table header. |
|
| 345 | - | #[derive(Clone, Copy, Debug)] |
|
| 346 | - | enum HeaderMode { |
|
| 347 | - | /// Print the header before the row. |
|
| 348 | - | Show, |
|
| 349 | - | /// Print only the data row. |
|
| 350 | - | Hide, |
|
| 351 | - | } |
|
| 352 | - | ||
| 353 | 338 | /// Parses the next argument as a `usize`. |
|
| 354 | 339 | fn next_usize(args: &mut impl Iterator<Item = String>, fallback: usize) -> usize { |
|
| 355 | 340 | args.next() |
|
| 356 | 341 | .and_then(|value| value.parse().ok()) |
|
| 357 | 342 | .unwrap_or(fallback) |
src/file_{file:04}.rs\n"
+0 -0
crates/tui/benches/render.rs
+34 -8
| 7 | 7 | ||
| 8 | 8 | use rustik_tui as tui; |
|
| 9 | 9 | use rustik_tui_widgets::{List, ScrollView, ScrollbarStyle, Selection, Viewport}; |
|
| 10 | 10 | ||
| 11 | 11 | use tui::{ |
|
| 12 | - | Border, Buffer, Cell, Color, Fill, HStack, Label, Length, Line, Rect, Style, Table, |
|
| 12 | + | Border, Buffer, Cell, Color, Constraint, Fill, HStack, Label, Length, Line, Rect, Style, Table, |
|
| 13 | 13 | TableOptions, VStack, Widget, |
|
| 14 | 14 | }; |
|
| 15 | 15 | ||
| 16 | 16 | const WORKLOAD: &str = "render"; |
|
| 17 | 17 | const AREA: Rect = Rect::new(0, 0, 640, 480); |
| 337 | 337 | 0x1_0000 + (usize::from(r) << 16) + (usize::from(g) << 8) + usize::from(b) |
|
| 338 | 338 | } |
|
| 339 | 339 | } |
|
| 340 | 340 | } |
|
| 341 | 341 | ||
| 342 | + | /// Prints the benchmark result as a styled terminal widget. |
|
| 342 | 343 | fn report(frames: usize, elapsed: Duration, checksum: usize) { |
|
| 343 | 344 | let seconds = elapsed.as_secs_f64(); |
|
| 344 | 345 | let fps = frames as f64 / seconds; |
|
| 345 | 346 | let cells = AREA.cols * AREA.rows * frames; |
|
| 346 | 347 | let mcells = cells as f64 / seconds / 1_000_000.0; |
|
| 347 | 348 | ||
| 348 | - | println!("{WORKLOAD}"); |
|
| 349 | - | println!(" frames: {frames}"); |
|
| 350 | - | println!(" area: {}x{}", AREA.cols, AREA.rows); |
|
| 351 | - | println!(" elapsed: {:.3}s", seconds); |
|
| 352 | - | println!(" rate: {:.1} frames/s", fps); |
|
| 353 | - | println!(" buffer: {:.1} Mcells/s", mcells); |
|
| 354 | - | println!(" checksum: {checksum:#x}"); |
|
| 349 | + | let mut table = Table::new(TableOptions { |
|
| 350 | + | spacing: 3, |
|
| 351 | + | ..TableOptions::default() |
|
| 352 | + | }); |
|
| 353 | + | table.push([ |
|
| 354 | + | Label::new(WORKLOAD).style(Style::default().bold()), |
|
| 355 | + | Label::from(format!("{fps:.1} frames/s")).fg(Color::White), |
|
| 356 | + | ]); |
|
| 357 | + | table.push([ |
|
| 358 | + | Label::new("frames").style(Style::default().bold()), |
|
| 359 | + | Label::from(format!("{frames}")).fg(Color::White), |
|
| 360 | + | ]); |
|
| 361 | + | table.push([ |
|
| 362 | + | Label::new("area").style(Style::default().bold()), |
|
| 363 | + | Label::from(format!("{}x{}", AREA.cols, AREA.rows)).fg(Color::White), |
|
| 364 | + | ]); |
|
| 365 | + | table.push([ |
|
| 366 | + | Label::new("elapsed").style(Style::default().bold()), |
|
| 367 | + | Label::from(format!("{seconds:.3}s")).fg(Color::White), |
|
| 368 | + | ]); |
|
| 369 | + | table.push([ |
|
| 370 | + | Label::new("buffer").style(Style::default().bold()), |
|
| 371 | + | Label::from(format!("{mcells:.1} Mcells/s")).fg(Color::White), |
|
| 372 | + | ]); |
|
| 373 | + | table.push([ |
|
| 374 | + | Label::new("checksum").style(Style::default().bold()), |
|
| 375 | + | Label::from(format!("{checksum:#x}")).fg(DIM_TEXT), |
|
| 376 | + | ]); |
|
| 377 | + | ||
| 378 | + | for line in table.lines(Constraint::UNBOUNDED) { |
|
| 379 | + | println!("{}", line.styled()); |
|
| 380 | + | } |
|
| 355 | 381 | } |