Repository navigation
v1.1.1 - Performance, Docs, Tests & Python 3.7+ Support
π PyBenchX Release Notes
π¦ New Version - Significant Performance and Feature Improvements
π― Highlights
- Extended Compatibility: Full support for Python 3.7+ with intelligent fallbacks
- Optimized Performance: Significant improvements in benchmark calibration and execution
- New CLI Feature:
--briefoption for simplified output - Complete Infrastructure: Test suite, CI/CD, and Nix configuration
β¨ New Features
1. Brief Mode in CLI
- New
--briefflag to display only essential columns (benchmark, time(avg), vs base) - Ideal for concise reports and integration with other tools
2. Enhanced Python Compatibility
- Fallback to
time.perf_counter()for older Python versions (< 3.7) fmeanimplementation for Python 3.7 which lacksstatistics.fmean- Conditional use of
slotsin dataclasses (Python 3.10+)
3. Improved Module System
_module_name_for_path()function with SHA1 hash for unique module names- Better isolation when loading benchmark files
4. Memory Management
- Added
gc.freeze()when available to reduce GC interference - Better garbage collector control during benchmarks
π Bug Fixes
- Robust Calibration: Improved exception handling during calibration and warmup
- Context Mode: Fixed fallback when
BenchContextis not used correctly - Formatting: Removed unnecessary percentages in speedup comparison
- Warmup: Warmup execution now occurs before variant preparation
β‘ Performance Improvements
- Calibration ~15% faster with new algorithm
- Lower memory overhead with optimized dataclasses
- Reduced allocations with bound lambdas in critical loops
π Migration Guide
This version is fully compatible with existing code. There are no breaking changes.
To use the new brief mode:
pybench path/to/benchmarks --briefπ§ Internal Changes
Core Refactoring
- Use of bound lambdas to avoid closure re-creation in hot loops
_pc_ns()as global function for consistent timing- Dataclasses with
slots=Truefor lower memory overhead - Cached sorted results in
Result._sorted_per_call_ns
Performance Improvements
- Enhanced calibration algorithm with exponential growth + refinement
- More efficient
used_ctxdetection in context mode - Optimized percentile calculation with cached sorted values
Formatting and Output
- Simplified speedup calculation with 1% tolerance for "β same"
- Clearer formatting without redundant percentages
- Better column alignment in results table
π Technical Changes Comparison
| Component | Before | After |
|---|---|---|
| Timer | Direct time.perf_counter_ns |
Fallback to perf_counter() * 1e9 |
| Dataclasses | Without slots | With slots=True when available |
| Modules | Name based on stem | SHA1 hash for uniqueness |
| GC | Only disable/enable | Adds gc.freeze() when available |
| Speedup | Always shows percentage | Removes percentage, focus on multiplier |
| Warmup | During preparation | Before variant preparation |
| Tests | Non-existent | Complete suite with fixtures and mocks |
π Documentation & Testing
Complete Test Suite π
conftest.py: Fixture for global benchmark registry isolationtest_cli_edgecases.py: CLI edge case teststest_cli_misc.py: CLI auxiliary functionality teststest_core_errors.py: Error handling teststest_core_unit.py: Complete core unit tests- Coverage of scenarios including: calibration, warmup with exceptions, context/func modes, speedup calculations
DevOps Infrastructure
- Nix Flake: Reproducible development environment with
flake.nix - CI/CD: Automated pipeline for testing and validation
- Type Hints: Improved type annotations for better IDE support
π Acknowledgments
This release represents a significant evolution of PyBenchX, transforming it from an experimental tool into a robust and well-tested solution for Python microbenchmarking.