diff --git a/benches/main.rs b/benches/main.rs index ea4670f..db1bba1 100644 --- a/benches/main.rs +++ b/benches/main.rs @@ -1,7 +1,9 @@ +use criterion::criterion_main; + pub mod main { - pub mod draw; - pub mod draw_results_list; + pub mod ui; } + pub use main::*; -criterion::criterion_main!(draw_results_list::benches, draw::benches,); +criterion_main!(ui::benches,); diff --git a/benches/main/draw.rs b/benches/main/draw.rs deleted file mode 100644 index 3b88bf3..0000000 --- a/benches/main/draw.rs +++ /dev/null @@ -1,62 +0,0 @@ -use criterion::{black_box, Criterion}; -use ratatui::backend::TestBackend; -use ratatui::layout::Rect; -use ratatui::Terminal; -use std::path::PathBuf; -use television::action::Action; -use television::channels::OnAir; -use television::channels::{files::Channel, TelevisionChannel}; -use television::config::{Config, ConfigEnv}; -use television::television::Television; -use tokio::runtime::Runtime; - -fn draw(c: &mut Criterion) { - let width = 250; - let height = 80; - - let rt = Runtime::new().unwrap(); - - c.bench_function("draw", |b| { - b.to_async(&rt).iter_batched( - // FIXME: this is kind of hacky - || { - let config = Config::new(&ConfigEnv::init().unwrap()).unwrap(); - let backend = TestBackend::new(width, height); - let terminal = Terminal::new(backend).unwrap(); - let (tx, _) = tokio::sync::mpsc::unbounded_channel(); - let mut channel = - TelevisionChannel::Files(Channel::new(vec![ - PathBuf::from("."), - ])); - channel.find("television"); - // Wait for the channel to finish loading - let mut tv = - Television::new(tx, channel, config, None, false, false); - for _ in 0..5 { - // tick the matcher - let _ = tv.channel.results(10, 0); - std::thread::sleep(std::time::Duration::from_millis(10)); - } - tv.select_next_entry(10); - let _ = tv.update_preview_state( - &tv.get_selected_entry(None).unwrap(), - ); - let _ = tv.update(&Action::Tick); - (tv, terminal) - }, - // Measurement - |(tv, mut terminal)| async move { - television::draw::draw( - black_box(&tv.dump_context()), - black_box(&mut terminal.get_frame()), - black_box(Rect::new(0, 0, width, height)), - ) - .unwrap(); - }, - criterion::BatchSize::SmallInput, - ); - }); -} - -criterion::criterion_group!(benches, draw); -criterion::criterion_main!(benches); diff --git a/benches/main/draw_results_list.rs b/benches/main/ui.rs similarity index 87% rename from benches/main/draw_results_list.rs rename to benches/main/ui.rs index 0c0b6e5..91ac5df 100644 --- a/benches/main/draw_results_list.rs +++ b/benches/main/ui.rs @@ -1,13 +1,24 @@ -use criterion::{criterion_group, Criterion}; +use criterion::criterion_group; +use criterion::{black_box, Criterion}; use devicons::FileIcon; +use ratatui::backend::TestBackend; use ratatui::layout::Alignment; +use ratatui::layout::Rect; use ratatui::prelude::{Line, Style}; use ratatui::style::Color; use ratatui::widgets::{Block, BorderType, Borders, ListDirection, Padding}; +use ratatui::Terminal; +use std::path::PathBuf; +use television::action::Action; use television::channels::entry::into_ranges; use television::channels::entry::{Entry, PreviewType}; +use television::channels::OnAir; +use television::channels::{files::Channel, TelevisionChannel}; +use television::config::{Config, ConfigEnv}; use television::screen::colors::ResultsColorscheme; use television::screen::results::build_results_list; +use television::television::Television; +use tokio::runtime::Runtime; pub fn draw_results_list(c: &mut Criterion) { // FIXME: there's probably a way to have this as a benchmark asset @@ -481,4 +492,52 @@ pub fn draw_results_list(c: &mut Criterion) { }); } -criterion_group!(benches, draw_results_list); +pub fn draw(c: &mut Criterion) { + let width = 250; + let height = 80; + + let rt = Runtime::new().unwrap(); + + c.bench_function("draw", |b| { + b.to_async(&rt).iter_batched( + // FIXME: this is kind of hacky + || { + let config = Config::new(&ConfigEnv::init().unwrap()).unwrap(); + let backend = TestBackend::new(width, height); + let terminal = Terminal::new(backend).unwrap(); + let (tx, _) = tokio::sync::mpsc::unbounded_channel(); + let mut channel = + TelevisionChannel::Files(Channel::new(vec![ + PathBuf::from("."), + ])); + channel.find("television"); + // Wait for the channel to finish loading + let mut tv = + Television::new(tx, channel, config, None, false, false); + for _ in 0..5 { + // tick the matcher + let _ = tv.channel.results(10, 0); + std::thread::sleep(std::time::Duration::from_millis(10)); + } + tv.select_next_entry(10); + let _ = tv.update_preview_state( + &tv.get_selected_entry(None).unwrap(), + ); + let _ = tv.update(&Action::Tick); + (tv, terminal) + }, + // Measurement + |(tv, mut terminal)| async move { + television::draw::draw( + black_box(&tv.dump_context()), + black_box(&mut terminal.get_frame()), + black_box(Rect::new(0, 0, width, height)), + ) + .unwrap(); + }, + criterion::BatchSize::SmallInput, + ); + }); +} + +criterion_group!(benches, draw_results_list, draw);