-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathstorage_bench.rs
More file actions
191 lines (165 loc) · 6.39 KB
/
Copy pathstorage_bench.rs
File metadata and controls
191 lines (165 loc) · 6.39 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
use std::time::Duration;
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use nexum_core::StorageEngine;
fn storage_write_throughput(c: &mut Criterion) {
let mut group = c.benchmark_group("storage_write");
// Test different data sizes
for size in [100, 1000, 10000, 100000].iter() {
group.throughput(Throughput::Elements(*size as u64));
group.bench_with_input(
BenchmarkId::new("sequential_writes", size),
size,
|b, &size| {
b.iter_batched(
|| StorageEngine::memory().unwrap(),
|engine| {
for i in 0..size {
let key = format!("key_{:06}", i);
let value = format!("value_{:06}_data_payload", i);
engine.set(key.as_bytes(), value.as_bytes()).unwrap();
}
black_box(())
},
criterion::BatchSize::SmallInput,
);
},
);
}
group.finish();
}
fn storage_read_throughput(c: &mut Criterion) {
let mut group = c.benchmark_group("storage_read");
for size in [100, 1000, 10000, 100000].iter() {
group.throughput(Throughput::Elements(*size as u64));
group.bench_with_input(
BenchmarkId::new("sequential_reads", size),
size,
|b, &size| {
b.iter_batched(
|| {
let engine = StorageEngine::memory().unwrap();
// Pre-populate with data
for i in 0..size {
let key = format!("key_{:06}", i);
let value = format!("value_{:06}_data_payload", i);
engine.set(key.as_bytes(), value.as_bytes()).unwrap();
}
engine
},
|engine| {
for i in 0..size {
let key = format!("key_{:06}", i);
black_box(engine.get(key.as_bytes()).unwrap());
}
},
criterion::BatchSize::SmallInput,
);
},
);
}
group.finish();
}
fn storage_mixed_workload(c: &mut Criterion) {
let mut group = c.benchmark_group("storage_mixed");
group.measurement_time(Duration::from_secs(10));
for ratio in [(70, 30), (50, 50), (30, 70)].iter() {
let (read_pct, write_pct) = ratio;
group.bench_with_input(
BenchmarkId::new("read_write_mix", format!("{}r_{}w", read_pct, write_pct)),
ratio,
|b, &(read_pct, _write_pct)| {
b.iter_batched(
|| {
let engine = StorageEngine::memory().unwrap();
// Pre-populate with some data
for i in 0..1000 {
let key = format!("key_{:06}", i);
let value = format!("value_{:06}", i);
engine.set(key.as_bytes(), value.as_bytes()).unwrap();
}
engine
},
|engine| {
for i in 0..1000 {
if i % 100 < read_pct {
// Read operation
let key = format!("key_{:06}", i % 1000);
black_box(engine.get(key.as_bytes()).unwrap());
} else {
// Write operation
let key = format!("key_{:06}", i + 1000);
let value = format!("new_value_{:06}", i);
engine.set(key.as_bytes(), value.as_bytes()).unwrap();
}
}
},
criterion::BatchSize::SmallInput,
);
},
);
}
group.finish();
}
fn storage_scan_prefix(c: &mut Criterion) {
let mut group = c.benchmark_group("storage_scan");
for prefix_size in [10, 100, 1000].iter() {
group.bench_with_input(
BenchmarkId::new("prefix_scan", prefix_size),
prefix_size,
|b, &prefix_size| {
b.iter_batched(
|| {
let engine = StorageEngine::memory().unwrap();
// Create data with different prefixes
for prefix in 0..10 {
for i in 0..prefix_size {
let key = format!("prefix_{}:item_{:06}", prefix, i);
let value = format!("data_{}", i);
engine.set(key.as_bytes(), value.as_bytes()).unwrap();
}
}
engine
},
|engine| {
black_box(engine.scan_prefix(b"prefix_5:").unwrap());
},
criterion::BatchSize::SmallInput,
);
},
);
}
group.finish();
}
fn storage_persistence_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("storage_persistence");
group.bench_function("flush_performance", |b| {
b.iter_batched(
|| {
let temp_dir = tempfile::tempdir().unwrap();
let engine = StorageEngine::new(temp_dir.path().join("bench_db")).unwrap();
// Write some data
for i in 0..1000 {
let key = format!("key_{:06}", i);
let value = format!("value_{:06}", i);
engine.set(key.as_bytes(), value.as_bytes()).unwrap();
}
(engine, temp_dir)
},
|(engine, _temp_dir)| {
engine.flush().unwrap();
black_box(())
},
criterion::BatchSize::SmallInput,
);
});
group.finish();
}
criterion_group!(
benches,
storage_write_throughput,
storage_read_throughput,
storage_mixed_workload,
storage_scan_prefix,
storage_persistence_benchmark
);
criterion_main!(benches);