Skip to content

Commit

Permalink
add: state saving benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nukesor committed Feb 22, 2025
1 parent ddab603 commit 195de37
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 1 deletion.
194 changes: 193 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ignore:
- "LICENSE"
- ".github"
- ".gitignore"
- "pueue/benches"

coverage:
status:
Expand Down
9 changes: 9 additions & 0 deletions pueue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ rust-version.workspace = true
[badges]
maintenance = { status = "actively-developed" }

[[bench]]
harness = false
name = "save_compressed_state"

[[bench]]
harness = false
name = "save_state"

[dependencies]
chrono.workspace = true
clap = { version = "4.5.30", features = [
Expand Down Expand Up @@ -55,6 +63,7 @@ tracing-subscriber = { version = "0.3.19", features = [
assert_cmd = "2"
assert_matches = "1"
better-panic.workspace = true
criterion = "0.5"
pretty_assertions.workspace = true
rstest = "0.24"
serde_yaml.workspace = true
Expand Down
43 changes: 43 additions & 0 deletions pueue/benches/save_compressed_state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use std::{collections::HashMap, env::vars, path::PathBuf};

use chrono::Local;
use criterion::{Criterion, criterion_group, criterion_main};
use pueue::daemon::internal_state::state::InternalState;
use pueue_lib::{Settings, Task, state::PUEUE_DEFAULT_GROUP};

/// Create a large state file with a few hundred tasks.
/// Save it to disk in compressed state
fn save_compressed_state() {
let dir = tempfile::tempdir().unwrap();
let mut settings = Settings::default();
settings.shared.pueue_directory = Some(dir.path().to_owned());
settings.daemon.compress_state_file = true;

let mut state = InternalState::new();

for _ in 0..400 {
let task = Task::new(
"ls".into(),
PathBuf::from("/tmp"),
HashMap::from_iter(vars()),
PUEUE_DEFAULT_GROUP.to_owned(),
pueue_lib::TaskStatus::Queued {
enqueued_at: Local::now(),
},
Vec::new(),
0,
None,
);

state.add_task(task);
}

state.save(&settings).unwrap();
}

pub fn state(crit: &mut Criterion) {
crit.bench_function("Save compressed state", |b| b.iter(save_compressed_state));
}

criterion_group!(benches, state);
criterion_main!(benches);
Loading

0 comments on commit 195de37

Please sign in to comment.