Skip to content

Commit 8acb272

Browse files
committed
wip
1 parent cb0ace5 commit 8acb272

File tree

13 files changed

+165
-2210
lines changed

13 files changed

+165
-2210
lines changed

module/move/benchkit/Cargo.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,32 @@ criterion_compat = [ "enabled", "dep:criterion" ] # Compatibility layer
6161
no_std = []
6262
use_alloc = [ "no_std" ]
6363

64+
# In workspace context, use:
65+
# [lints]
66+
# workspace = true
67+
68+
# For standalone development, define lints inline:
69+
[lints.rust]
70+
rust_2018_idioms = { level = "warn", priority = -1 }
71+
future_incompatible = { level = "warn", priority = -1 }
72+
missing_docs = "warn"
73+
missing_debug_implementations = "warn"
74+
unsafe-code = "deny"
75+
76+
[lints.clippy]
77+
pedantic = { level = "warn", priority = -1 }
78+
undocumented_unsafe_blocks = "deny"
79+
std_instead_of_core = "warn"
80+
doc_include_without_cfg = "warn"
81+
missing_inline_in_public_items = "allow"
82+
6483
[dependencies]
6584
# Core dependencies - always available
85+
# Note: In workspace context, use:
86+
# error_tools = { workspace = true, features = [ "enabled" ] }
87+
# mod_interface = { workspace = true }
88+
# For standalone development:
89+
error_tools = { git = "https://github.com/Wandalen/wTools", branch = "alpha", features = [ "enabled" ] }
6690

6791
# Feature-gated dependencies
6892
pulldown-cmark = { version = "0.10", optional = true }
@@ -74,6 +98,10 @@ criterion = { version = "0.5", optional = true }
7498
chrono = { version = "0.4", features = ["serde"], optional = true }
7599

76100
[dev-dependencies]
101+
# In workspace context, use:
102+
# test_tools = { workspace = true }
103+
# tempfile = { workspace = true }
104+
# For standalone development:
77105
tempfile = "3.0"
78106

79107
# Examples will be added as implementation progresses

module/move/benchkit/readme.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,30 @@ fn main() {
2929
```rust
3030
use benchkit::prelude::*;
3131

32+
fn generate_random_vec(size: usize) -> Vec<u32> {
33+
(0..size).map(|x| x as u32).collect()
34+
}
35+
3236
fn main() {
3337
let mut comparison = ComparativeAnalysis::new("sorting_algorithms");
3438

3539
// Compare different sorting approaches
3640
for size in [100, 1000, 10000] {
3741
let data = generate_random_vec(size);
3842

39-
comparison.add_variant(&format!("std_sort_{}", size), {
43+
comparison = comparison.algorithm(&format!("std_sort_{}", size), {
4044
let mut d = data.clone();
41-
move || d.sort()
45+
move || { d.sort(); }
4246
});
4347

44-
comparison.add_variant(&format!("unstable_sort_{}", size), {
48+
comparison = comparison.algorithm(&format!("unstable_sort_{}", size), {
4549
let mut d = data.clone();
46-
move || d.sort_unstable()
50+
move || { d.sort_unstable(); }
4751
});
4852
}
4953

5054
let report = comparison.run();
51-
report.print_summary();
55+
println!("Fastest: {:?}", report.fastest());
5256
}
5357
```
5458

@@ -135,11 +139,22 @@ Perfect for ad-hoc performance analysis:
135139
```rust
136140
use benchkit::prelude::*;
137141

142+
fn old_algorithm(data: &[u32]) -> u32 {
143+
data.iter().sum()
144+
}
145+
146+
fn new_algorithm(data: &[u32]) -> u32 {
147+
data.iter().fold(0, |acc, x| acc + x)
148+
}
149+
150+
let data = vec![1, 2, 3, 4, 5];
151+
138152
// Quick check - is this optimization working?
139153
let before = bench_once(|| old_algorithm(&data));
140154
let after = bench_once(|| new_algorithm(&data));
141155

142-
println!("Improvement: {:.1}%", before.compare(&after).improvement());
156+
let comparison = before.compare(&after);
157+
println!("Improvement: {:.1}%", comparison.improvement_percentage);
143158
```
144159

145160
### Pattern 2: Comprehensive Analysis
@@ -149,26 +164,38 @@ For thorough performance characterization:
149164
```rust
150165
use benchkit::prelude::*;
151166

167+
fn generate_test_data(size: usize) -> Vec<u32> {
168+
(0..size).map(|x| x as u32).collect()
169+
}
170+
171+
fn run_algorithm(algorithm: &str, data: &[u32]) -> u32 {
172+
match algorithm {
173+
"baseline" => data.iter().sum(),
174+
"optimized" => data.iter().fold(0, |acc, x| acc + x),
175+
"simd" => data.iter().sum::<u32>(),
176+
_ => 0,
177+
}
178+
}
179+
152180
fn analyze_performance() {
153181
let mut suite = BenchmarkSuite::new("comprehensive_analysis");
154182

155183
// Test across multiple dimensions
156184
for size in [10, 100, 1000, 10000] {
157185
for algorithm in ["baseline", "optimized", "simd"] {
158186
let data = generate_test_data(size);
159-
suite.benchmark(&format!("{}_size_{}", algorithm, size), || {
160-
run_algorithm(algorithm, &data)
187+
let alg = algorithm.to_string();
188+
suite.benchmark(&format!("{}_size_{}", algorithm, size), move || {
189+
run_algorithm(&alg, &data);
161190
});
162191
}
163192
}
164193

165194
let analysis = suite.run_analysis();
166195

167196
// Generate comprehensive report
168-
analysis.generate_report()
169-
.with_scaling_analysis()
170-
.with_recommendations()
171-
.save_markdown("performance_analysis.md");
197+
let report = analysis.generate_markdown_report();
198+
println!("{}", report.generate());
172199
}
173200
```
174201

module/move/benchkit/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
//! // Simple timing measurement
2121
//! let result = bench_function("my_operation", || {
2222
//! // Your code here
23-
//! std::thread::sleep(std::time::Duration::from_millis(1));
23+
//! std::hint::black_box(42 + 42);
2424
//! });
2525
//!
26-
//! println!("Average time: {:.2?}", result.mean_time());
26+
//! println!("Average time: {:?}", result.mean_time());
2727
//! ```
2828
//!
2929
//! ## Features

module/move/benchkit/src/reporting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl MarkdownUpdater {
2424
}
2525

2626
/// Update the section with new content
27-
pub fn update_section(&self, content: &str) -> Result<(), std::io::Error> {
27+
pub fn update_section(&self, content: &str) -> error_tools::Result<()> {
2828
// Read existing file or create empty content
2929
let existing_content = if self.file_path.exists() {
3030
std::fs::read_to_string(&self.file_path)?
@@ -251,7 +251,7 @@ impl ReportGenerator {
251251
}
252252

253253
/// Update markdown file section with report
254-
pub fn update_markdown_file(&self, file_path: impl AsRef<Path>, section_name: &str) -> Result<(), std::io::Error> {
254+
pub fn update_markdown_file(&self, file_path: impl AsRef<Path>, section_name: &str) -> error_tools::Result<()> {
255255
let updater = MarkdownUpdater::new(file_path, section_name);
256256
let content = self.generate_comprehensive_report();
257257
updater.update_section(&content)
@@ -300,7 +300,7 @@ pub mod quick {
300300
file_path: impl AsRef<Path>,
301301
section_name: &str,
302302
title: &str
303-
) -> Result<(), std::io::Error> {
303+
) -> error_tools::Result<()> {
304304
let generator = ReportGenerator::new(title, results.clone());
305305
generator.update_markdown_file(file_path, section_name)
306306
}

module/move/benchkit/src/suite.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl SuiteResults {
126126
}
127127

128128
/// Save results as new baseline
129-
pub fn save_as_baseline(&self, _baseline_file: impl AsRef<std::path::Path>) -> Result<(), std::io::Error> {
129+
pub fn save_as_baseline(&self, _baseline_file: impl AsRef<std::path::Path>) -> error_tools::Result<()> {
130130
// TODO: Implement saving to JSON/TOML file
131131
// For now, just succeed
132132
Ok(())
@@ -236,17 +236,18 @@ impl MarkdownReport {
236236
&self,
237237
file_path: impl AsRef<std::path::Path>,
238238
section_name: &str
239-
) -> Result<(), Box<dyn std::error::Error>> {
239+
) -> error_tools::Result<()> {
240240
// TODO: Implement markdown file section updating
241241
// This would parse existing markdown, find section, and replace content
242242
println!("Would update {} section in {:?}", section_name, file_path.as_ref());
243243
Ok(())
244244
}
245245

246246
/// Save report to file
247-
pub fn save(&self, file_path: impl AsRef<std::path::Path>) -> Result<(), std::io::Error> {
247+
pub fn save(&self, file_path: impl AsRef<std::path::Path>) -> error_tools::Result<()> {
248248
let content = self.generate();
249-
std::fs::write(file_path, content)
249+
std::fs::write(file_path, content)?;
250+
Ok(())
250251
}
251252
}
252253

0 commit comments

Comments
 (0)