aboutsummaryrefslogtreecommitdiffstats
path: root/benches
diff options
context:
space:
mode:
authorDaniel Jankowski <daniel.jankowski@rub.de>2023-12-26 12:07:33 +0100
committerDaniel Jankowski <daniel.jankowski@rub.de>2023-12-26 12:07:33 +0100
commit7e939328f9ec45fbcd856474dd7c464e3ff402bb (patch)
tree9bb682a5d63c4214d14d6ab25f80091a54c64bea /benches
parentchore: update cargo deps (diff)
downloadsl0pstatus-7e939328f9ec45fbcd856474dd7c464e3ff402bb.tar.gz
sl0pstatus-7e939328f9ec45fbcd856474dd7c464e3ff402bb.tar.xz
sl0pstatus-7e939328f9ec45fbcd856474dd7c464e3ff402bb.zip
feat: implement cache for dynamic command rendering
Diffstat (limited to 'benches')
-rw-r--r--benches/benches.rs37
-rw-r--r--benches/widgets.rs2
2 files changed, 37 insertions, 2 deletions
diff --git a/benches/benches.rs b/benches/benches.rs
index ee6d577..1435b87 100644
--- a/benches/benches.rs
+++ b/benches/benches.rs
@@ -4,7 +4,9 @@ use zellij_tile::prelude::{ModeInfo, TabInfo};
use zjstatus::{
config::{ModuleConfig, ZellijState},
- render::FormattedPart,
+ render::{
+ formatted_part_from_string_cached, formatted_parts_from_string_cached, FormattedPart,
+ },
widgets::{datetime::DateTimeWidget, mode::ModeWidget, session::SessionWidget, widget::Widget},
};
@@ -108,6 +110,36 @@ fn bench_formattedpart_from_format_string(c: &mut Criterion) {
});
}
+fn bench_formattedpart_from_format_string_cached(c: &mut Criterion) {
+ c.bench_function("formatted_part_from_string_cached", |b| {
+ b.iter(|| {
+ formatted_part_from_string_cached(
+ "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] ",
+ )
+ })
+ });
+}
+
+fn bench_formattedpart_multiple_from_format_string(c: &mut Criterion) {
+ c.bench_function("FormattedPart::multiple_from_format_string", |b| {
+ b.iter(|| {
+ FormattedPart::multiple_from_format_string(
+ "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] #[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] ",
+ )
+ })
+ });
+}
+
+fn bench_formattedparts_from_format_string_cached(c: &mut Criterion) {
+ c.bench_function("formatted_parts_from_string_cached", |b| {
+ b.iter(|| {
+ formatted_parts_from_string_cached(
+ "#[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] #[fg=#9399B2,bg=#181825,bold,italic] {index} {name} [] ",
+ )
+ })
+ });
+}
+
fn bench_moduleconfig_new(c: &mut Criterion) {
let mut config = BTreeMap::new();
@@ -122,6 +154,9 @@ fn bench_moduleconfig_new(c: &mut Criterion) {
fn criterion_benchmark(c: &mut Criterion) {
bench_formattedpart_from_format_string(c);
+ bench_formattedpart_from_format_string_cached(c);
+ bench_formattedpart_multiple_from_format_string(c);
+ bench_formattedparts_from_format_string_cached(c);
bench_formattedpart_format_string_with_widgets(c);
bench_moduleconfig_new(c);
bench_moduleconfig_render_bar(c);
diff --git a/benches/widgets.rs b/benches/widgets.rs
index 1148cdb..d8d6212 100644
--- a/benches/widgets.rs
+++ b/benches/widgets.rs
@@ -63,7 +63,7 @@ fn bench_widget_command_dynamic(c: &mut Criterion) {
"command_test".to_owned(),
widgets::command::CommandResult {
exit_code: Some(0),
- stdout: "#[fg=#9399B2,bg=#181825,bold,italic] test".to_owned(),
+ stdout: "#[fg=#9399B2,bg=#181825,bold,italic] test #[fg=#9399B2,bg=#181825,bold,italic] test".to_owned(),
stderr: "".to_owned(),
context: BTreeMap::from([(
"timestamp".to_owned(),