diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 12:54:03 +0100 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-12-17 12:54:03 +0100 |
| commit | c9dc2f52d9bb8b6727b59136f77a3beb8cef9128 (patch) | |
| tree | 05a113555867ec8a2229a5cd86aed89ee8297f2d | |
| parent | feat: refactor to lib and add benches (diff) | |
| download | sl0pstatus-c9dc2f52d9bb8b6727b59136f77a3beb8cef9128.tar.gz sl0pstatus-c9dc2f52d9bb8b6727b59136f77a3beb8cef9128.tar.xz sl0pstatus-c9dc2f52d9bb8b6727b59136f77a3beb8cef9128.zip | |
feat: add more benches for widgets
| -rw-r--r-- | benches/widgets.rs | 64 | ||||
| -rw-r--r-- | justfile | 2 |
2 files changed, 60 insertions, 6 deletions
diff --git a/benches/widgets.rs b/benches/widgets.rs index ee678cc..05ba586 100644 --- a/benches/widgets.rs +++ b/benches/widgets.rs @@ -1,9 +1,61 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use zjstatus::config::ZellijState; use std::collections::BTreeMap; +use zellij_tile::prelude::*; -use zjstatus::widgets; -use zjstatus::widgets::widget::Widget; +use zjstatus::{ + config::ZellijState, + widgets::{self, widget::Widget}, +}; + +fn bench_widget_tabs(c: &mut Criterion) { + let config = BTreeMap::from([ + ( + "tab_normal".to_string(), + "#[fg=#6C7086,bg=#181825] {index} {name} ".to_string(), + ), + ( + "tab_normal_fullscreen".to_string(), + "#[fg=#6C7086,bg=#181825] {index} {name} ".to_string(), + ), + ( + "tab_active".to_string(), + "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} ".to_string(), + ), + ]); + + let wid = widgets::tabs::TabsWidget::new(config); + + let mut tab_state = TabInfo::default(); + tab_state.name = "test".to_string(); + tab_state.active = true; + + let mut state = ZellijState::default(); + state.tabs = vec![tab_state]; + + c.bench_function("widgets::TabsWidget", |b| { + b.iter(|| { + wid.process("tabs", state.clone()); + }) + }); +} + +fn bench_widget_mod(c: &mut Criterion) { + let config = BTreeMap::from([( + "mode_normal".to_string(), + "#[bg=blue] #[bg=yellow] ".to_string(), + )]); + + let wid = widgets::mode::ModeWidget::new(config); + + let mut state = ZellijState::default(); + state.mode = ModeInfo::default(); + + c.bench_function("widgets::ModeWidget", |b| { + b.iter(|| { + wid.process("mode", state.clone()); + }) + }); +} fn bench_widget_datetime(c: &mut Criterion) { let config = BTreeMap::new(); @@ -12,15 +64,17 @@ fn bench_widget_datetime(c: &mut Criterion) { let state = ZellijState::default(); - c.bench_function("widgets::DateTime", |b| { + c.bench_function("widgets::DateTimeWidget", |b| { b.iter(|| { - wid.process("", state.clone()); + wid.process("datetime", state.clone()); }) }); } fn criterion_benchmark(c: &mut Criterion) { bench_widget_datetime(c); + bench_widget_mod(c); + bench_widget_tabs(c); } criterion_group!(benches, criterion_benchmark); @@ -1,5 +1,5 @@ bench: - cargo wasi bench -- + cargo wasi bench -- --color always | grep --color=never -v "Criterion.rs ERROR" build: cargo build |
