-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperation_benchmarks.rs
More file actions
105 lines (87 loc) · 2.83 KB
/
Copy pathoperation_benchmarks.rs
File metadata and controls
105 lines (87 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// SPDX-License-Identifier: MPL-2.0
//! Benchmarks for core filesystem operations
//!
//! Measures the performance of mkdir, rmdir, touch, rm, and operation sequences.
//!
//! Run with:
//! ```bash
//! cargo bench
//! ```
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tempfile::tempdir;
use vsh::commands::{mkdir, rm, rmdir, touch};
use vsh::state::ShellState;
/// Benchmark: mkdir operation
fn bench_mkdir(c: &mut Criterion) {
c.bench_function("mkdir", |b| {
b.iter(|| {
let temp = tempdir().unwrap();
let mut state = ShellState::new(temp.path().to_str().unwrap()).unwrap();
// Create directory
mkdir(&mut state, "test_dir", false).unwrap();
black_box(&state);
});
});
}
/// Benchmark: mkdir + rmdir (reversibility)
fn bench_mkdir_rmdir(c: &mut Criterion) {
c.bench_function("mkdir_rmdir_reversible", |b| {
b.iter(|| {
let temp = tempdir().unwrap();
let mut state = ShellState::new(temp.path().to_str().unwrap()).unwrap();
mkdir(&mut state, "test_dir", false).unwrap();
rmdir(&mut state, "test_dir", false).unwrap();
black_box(&state);
});
});
}
/// Benchmark: touch operation
fn bench_touch(c: &mut Criterion) {
c.bench_function("touch", |b| {
b.iter(|| {
let temp = tempdir().unwrap();
let mut state = ShellState::new(temp.path().to_str().unwrap()).unwrap();
touch(&mut state, "test_file.txt", false).unwrap();
black_box(&state);
});
});
}
/// Benchmark: touch + rm (reversibility)
fn bench_touch_rm(c: &mut Criterion) {
c.bench_function("touch_rm_reversible", |b| {
b.iter(|| {
let temp = tempdir().unwrap();
let mut state = ShellState::new(temp.path().to_str().unwrap()).unwrap();
touch(&mut state, "test_file.txt", false).unwrap();
rm(&mut state, "test_file.txt", false).unwrap();
black_box(&state);
});
});
}
/// Benchmark: multiple operations (sequence)
fn bench_operation_sequence(c: &mut Criterion) {
c.bench_function("operation_sequence_5", |b| {
b.iter(|| {
let temp = tempdir().unwrap();
let mut state = ShellState::new(temp.path().to_str().unwrap()).unwrap();
// Create 5 directories
for i in 0..5 {
mkdir(&mut state, &format!("dir{}", i), false).unwrap();
}
// Delete them
for i in 0..5 {
rmdir(&mut state, &format!("dir{}", i), false).unwrap();
}
black_box(&state);
});
});
}
criterion_group!(
benches,
bench_mkdir,
bench_mkdir_rmdir,
bench_touch,
bench_touch_rm,
bench_operation_sequence
);
criterion_main!(benches);