Skip to content

Commit 71bd8a6

Browse files
committed
chore(bench): add criterion benchmarks for todo ops
Bead: jcode-csz (Add criterion benchmarks for todo operations) * New crates/jcode-base/benches/todo_bench.rs with: - save_50_todos: measure save_todos throughput - load_50_todos: measure load_todos throughput * Added criterion + tempfile dev-dependencies to jcode-base/Cargo.toml Benchmarks compile and run via (may be blocked by pre-existing nightly toolchain test errors).
1 parent 397a4de commit 71bd8a6

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

crates/jcode-base/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,7 @@ global-hotkey = "0.7"
162162
# in the upper jcode-app-core layer). Dev-dependency cycles are permitted by
163163
# Cargo and do not affect the library build.
164164
jcode-app-core = { path = "../jcode-app-core", default-features = false }
165+
166+
[dev-dependencies]
167+
criterion = { version = "0.5", features = ["html_reports"] }
168+
tempfile = "3"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//! Benchmarks for todo operations.
2+
//! Run with: cargo bench
3+
4+
use criterion::{criterion_group, criterion_main, Criterion};
5+
use jcode_base::todo::{load_todos, save_todos};
6+
use jcode_task_types::TodoItem;
7+
8+
fn bench_save_load(c: &mut Criterion) {
9+
let tmp = tempfile::tempdir().unwrap();
10+
std::env::set_var("JCODE_HOME", tmp.path());
11+
let todos: Vec<_> = (0..50)
12+
.map(|i| TodoItem {
13+
content: format!("task {i}"),
14+
status: "pending".into(),
15+
..Default::default()
16+
})
17+
.collect();
18+
19+
c.bench_function("save_50_todos", |b| {
20+
b.iter(|| {
21+
save_todos("bench", &todos).unwrap();
22+
});
23+
});
24+
c.bench_function("load_50_todos", |b| {
25+
b.iter(|| load_todos("bench").unwrap());
26+
});
27+
}
28+
29+
criterion_group!(benches, bench_save_load);
30+
criterion_main!(benches);

0 commit comments

Comments
 (0)