Skip to content

Commit b60e3c7

Browse files
committed
refactor: Standardize benchkit and unilang project structure
- Migrate benchmarks from tests/ to standard benches/ directory - Update benchkit documentation to promote benches/ compliance - Implement benchkit directory validation and error messaging - Add comprehensive benchmark organization with proper cargo integration - Move completed tasks to appropriate directories for better organization - Clean up obsolete benchmark scripts and configuration files - Enhance unilang library structure with new analysis modules - Add performance documentation and optimization guides
1 parent 425a74d commit b60e3c7

File tree

75 files changed

+6034
-752
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+6034
-752
lines changed

module/core/test_tools/src/standalone.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub mod error_tools {
9292
pub use crate::{debug_assert_id, debug_assert_identical, debug_assert_ni, debug_assert_not_identical};
9393
}
9494

95-
/// Untyped error handling for error_tools compatibility
95+
/// Untyped error handling for `error_tools` compatibility
9696
#[cfg(feature = "standalone_error_tools")]
9797
pub mod untyped {
9898
// Re-export anyhow functionality for untyped error tests
@@ -692,8 +692,8 @@ pub mod mem_tools {
692692

693693
/// Compare if two references point to the same memory
694694
pub fn same_ptr<T1: ?Sized, T2: ?Sized>(src1: &T1, src2: &T2) -> bool {
695-
let ptr1 = std::ptr::from_ref(src1).cast::<()>();
696-
let ptr2 = std::ptr::from_ref(src2).cast::<()>();
695+
let ptr1 = core::ptr::from_ref(src1).cast::<()>();
696+
let ptr2 = core::ptr::from_ref(src2).cast::<()>();
697697
ptr1 == ptr2
698698
}
699699

@@ -718,7 +718,7 @@ pub mod mem_tools {
718718
}
719719

720720
/// Compare if two references point to the same memory region
721-
/// This function accepts any sized or unsized types like the real mem_tools implementation
721+
/// This function accepts any sized or unsized types like the real `mem_tools` implementation
722722
pub fn same_region<T1: ?Sized, T2: ?Sized>(src1: &T1, src2: &T2) -> bool {
723723
same_ptr(src1, src2) && same_size(src1, src2)
724724
}

module/move/benchkit/examples/cargo_bench_integration.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ fn main() {
347347
println!("====================================");
348348
println!("✅ Seamless `cargo bench` integration (MANDATORY)");
349349
println!("✅ Automatic documentation updates during benchmarks");
350-
println!("✅ Standard `benches/` directory support");
350+
println!("✅ MANDATORY `benches/` directory usage (NO ALTERNATIVES)");
351351
println!("✅ Criterion compatibility for zero-migration adoption");
352352
println!("✅ CI/CD integration with standard workflows");
353353
println!("✅ Regression analysis built into benchmark process");
@@ -361,7 +361,13 @@ fn main() {
361361
println!("4. **Migration Friendly**: Existing criterion projects can adopt easily");
362362
println!("5. **Production Ready**: Suitable for CI/CD and enterprise environments");
363363

364-
println!("\n🚨 WITHOUT THESE FEATURES, BENCHKIT WILL FAIL TO ACHIEVE ADOPTION!");
364+
println!("\n🚨 CRITICAL WARNING:");
365+
println!("===================");
366+
println!("ALL benchmarks MUST be in benches/ directory - NO EXCEPTIONS!");
367+
println!("❌ NEVER put benchmarks in tests/ - they are NOT tests!");
368+
println!("❌ NEVER put benchmarks in examples/ - they are NOT demonstrations!");
369+
println!("✅ ONLY benches/ directory is acceptable for benchmark files!");
370+
println!();
365371
println!("The Rust community expects `cargo bench` to work. This is non-negotiable.");
366372
}
367373

module/move/benchkit/readme.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -758,25 +758,31 @@ fn main() -> Result< (), Box< dyn std::error::Error > >
758758
[ 5. Commit Code + Perf Docs ] <- [ 4. Auto-Update `benchmark_results.md` ] <- [ Analyze Results ]
759759
```
760760

761-
## 📁 Why Not `benches/`? Standard Directory Integration
761+
## 📁 MANDATORY `benches/` Directory - NO ALTERNATIVES
762762

763-
The traditional `benches/` directory creates artificial separation between ALL your benchmark content and the standard Rust project structure. `benchkit` encourages you to use standard directories for ALL benchmark-related files:
763+
**ABSOLUTE REQUIREMENT**: ALL benchmark-related files MUST be in the `benches/` directory. This is NON-NEGOTIABLE for proper benchkit functionality:
764764

765-
-**Use `tests/`**: Performance benchmarks alongside unit tests
766-
-**Use `examples/`**: Demonstration benchmarks and showcases
767-
-**Use `src/bin/`**: Dedicated benchmark executables
768-
-**Standard integration**: Keep ALL benchmark content in standard Rust directories
769-
-**Avoid `benches/`**: Don't isolate ANY benchmark files in framework-specific directories
765+
- 🚫 **NEVER in `tests/`**: Benchmarks are NOT tests and MUST NOT be mixed with unit tests
766+
- 🚫 **NEVER in `examples/`**: Examples are demonstrations, NOT performance measurements
767+
- 🚫 **NEVER in `src/bin/`**: Source binaries are NOT benchmarks
768+
-**ONLY in `benches/`**: This is the EXCLUSIVE location for ALL benchmark content
769+
770+
**Why This Requirement Exists:**
771+
772+
-**Cargo Requirement**: `cargo bench` ONLY works with `benches/` directory
773+
- 🏗️ **Ecosystem Standard**: ALL professional Rust projects use `benches/` EXCLUSIVELY
774+
- 🔧 **Tool Compatibility**: IDEs, CI systems, linters expect benchmarks ONLY in `benches/`
775+
- 📊 **Performance Isolation**: Benchmarks require different compilation and execution than tests
770776

771777
### Why This Matters
772778

773-
**Workflow Integration**: ALL benchmark content should be part of regular development, not isolated in framework-specific directories.
779+
**Ecosystem Integration**: The `benches/` directory is the official Rust standard, ensuring compatibility with the entire Rust toolchain.
774780

775-
**Documentation Proximity**: ALL benchmark files are documentation - keep them integrated with your standard project structure for better maintainability.
781+
**Zero Configuration**: `cargo bench` automatically discovers and runs benchmarks in the `benches/` directory without additional setup.
776782

777-
**Testing Philosophy**: Performance is part of correctness validation - integrate benchmarks with your existing test suite.
783+
**Community Expectations**: Developers expect to find benchmarks in `benches/` - this follows the principle of least surprise.
778784

779-
**Toolkit vs Framework**: Frameworks enforce rigid `benches/` isolation; toolkits integrate with your existing project structure.
785+
**Tool Compatibility**: All Rust tooling (IDEs, CI/CD, linters) is designed around the standard `benches/` structure.
780786

781787
### Automatic Documentation Updates
782788

module/move/benchkit/spec.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,12 @@ if line.trim() == self.section_marker.trim() {
278278

279279
### 8. Standard Directory Requirements
280280

281-
**SR-DIRECTORY-1: Standard Rust Convention Compliance****MANDATORY**
282-
- ALL benchmark-related files must be located in the standard `benches/` directory
283-
- This follows established Rust ecosystem conventions and ensures compatibility with `cargo bench`
284-
- Benchmark binaries, data generation scripts, and analysis tools must all reside in `benches/`
285-
- No benchmark-related files should be placed in `tests/`, `examples/`, or `src/bin/`
281+
**SR-DIRECTORY-1: ABSOLUTE `benches/` Directory Requirement****MANDATORY - NO EXCEPTIONS**
282+
- ALL benchmark-related files MUST be located EXCLUSIVELY in the `benches/` directory
283+
- This is NON-NEGOTIABLE for cargo bench compatibility and ecosystem standards
284+
- Benchmark binaries, data generation scripts, and analysis tools MUST ALL reside in `benches/`
285+
- 🚫 **STRICTLY PROHIBITED**: ANY benchmark files in `tests/`, `examples/`, or `src/bin/`
286+
- 🚫 **ENFORCEMENT**: benchkit will ERROR if benchmarks detected outside `benches/`
286287

287288
**SR-DIRECTORY-2: Automatic Documentation Generation****MANDATORY**
288289
- `benches/readme.md` must be automatically generated and updated with benchmark results

module/move/benchkit/src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ fn check_directory_recommendations()
4444
#[ cfg( debug_assertions ) ]
4545
if let Ok( current_dir ) = std::env::current_dir()
4646
{
47-
if current_dir.file_name()
48-
.and_then( | n | n.to_str() )
49-
.is_some_and( | s | s == "benches" )
47+
if let Some( dir_name ) = current_dir.file_name().and_then( | n | n.to_str() )
5048
{
51-
eprintln!( "💡 benchkit: Running in standard benches/ directory ✅" );
52-
eprintln!( " Remember to update benches/readme.md with your benchmark results" );
53-
eprintln!( " Use MarkdownUpdater to automatically maintain comprehensive reports" );
54-
eprintln!( " See: https://docs.rs/benchkit#standard-benches-directory-integration" );
49+
if dir_name == "benches"
50+
{
51+
eprintln!( "✅ benchkit: Running in REQUIRED benches/ directory - CORRECT!" );
52+
eprintln!( " Remember to update benches/readme.md with your benchmark results" );
53+
eprintln!( " Use MarkdownUpdater to automatically maintain comprehensive reports" );
54+
eprintln!( " See: https://docs.rs/benchkit#mandatory-benches-directory" );
55+
}
56+
else if dir_name == "tests" || dir_name == "examples" || dir_name == "src"
57+
{
58+
eprintln!( "❌ benchkit ERROR: Benchmarks MUST be in benches/ directory!" );
59+
eprintln!( " Current location: {}/", dir_name );
60+
eprintln!( " REQUIRED: Move ALL benchmark files to benches/ directory" );
61+
eprintln!( " Benchmarks are NOT tests - they belong in benches/ ONLY" );
62+
eprintln!( " See: https://docs.rs/benchkit#mandatory-benches-directory" );
63+
}
5564
}
5665
}
5766
}

0 commit comments

Comments
 (0)