gcubed.performance_regression
Benchmark and compare G-Cubed model-solution performance.
The benchmark runs each trial in a fresh Python process with memory profiling disabled. This keeps production runtime measurements separate from instrumented memory profiles, whose event collection adds overhead of its own.
Model build required for memory-reduction performance evidence.
Minimum number of fresh-process benchmark trials in an accepted result.
Default median slowdown that triggers explicit performance review.
Execution-policy settings recorded without requiring them to match.
Focused build-197 test used by a performance benchmark scope.
Attributes:
test_path: Test-file path relative to the repository root.
selector: Pytest -k selector for the measured construction path.
Benchmark scopes and their focused real-model pytest tests.
Validate and split a build-197 benchmark model identifier.
Args:
model_id: Model identifier in <VERSION>_<BUILD> form.
Returns: A tuple containing model version and build.
Raises:
ValueError: Raised when the model ID is malformed or does not use build
197.
Calculate summary statistics for benchmark trial durations.
Args: durations_seconds: Positive wall-clock durations in seconds.
Returns: Mean, median, minimum, maximum, and population standard deviation.
Raises: ValueError: Raised when no durations are supplied or a duration is not positive.
Build the focused pytest command for one benchmark trial.
Args:
model_id: Build-197 model identifier.
scope: One of the keys in :data:BENCHMARK_SCOPES.
repository_root: Optional gcubedcode repository root. The source
checkout containing this module is used when omitted.
Returns:
Command arguments suitable for subprocess.run.
Raises: ValueError: Raised for a malformed model ID, a non-197 build, or an unsupported scope. FileNotFoundError: Raised when the focused test file is unavailable.
Run a production-mode performance benchmark in fresh processes.
Args:
model_id: Build-197 model identifier, normally 6W_197.
scope: Benchmark scope, such as state-space-form.
repetitions: Number of measured fresh-process trials. Must be at least
:data:MINIMUM_REPETITIONS.
label: Optional experiment label such as before_sparse_storage.
output_file: Optional JSON artifact path.
repository_root: Optional gcubedcode repository root.
Returns: JSON-compatible benchmark result containing every trial and summary timing statistics.
Raises: ValueError: Raised for invalid model, scope, or repetition values. FileNotFoundError: Raised when the benchmark test file is unavailable. RuntimeError: Raised when a benchmark subprocess fails. OSError: Propagated when a subprocess cannot be started or the result artifact cannot be written.
Compare pre-change and post-change performance benchmark results.
Args: reference: Pre-change benchmark result. candidate: Post-change benchmark result. max_median_slowdown_percent: Largest accepted candidate median slowdown.
Returns:
JSON-compatible report. passed is false when the median slowdown
exceeds the supplied threshold.
Raises: ValueError: Raised when the threshold is negative, results are incompatible, use a non-197 build, contain too few trials, were run with memory profiling, or came from different environments. KeyError: Raised when a required result field is absent. TypeError: Raised when required result values have incompatible types.
Read, compare, and optionally report two benchmark artifacts.
Args: reference_file: Pre-change benchmark JSON path. candidate_file: Post-change benchmark JSON path. report_file: Optional comparison-report JSON path. max_median_slowdown_percent: Largest accepted median slowdown.
Returns: JSON-compatible performance comparison report.
Raises: FileNotFoundError: Raised when either benchmark file is missing. OSError: Propagated when benchmark or report files cannot be read or written. json.JSONDecodeError: Raised when a benchmark file is not valid JSON. ValueError: Propagated when results are not comparable. KeyError: Propagated when a required result field is absent. TypeError: Propagated when required values have incompatible types.
Run the performance-regression command-line interface.
Args:
argv: Optional argument sequence. argparse reads sys.argv when
omitted.
Returns:
Process exit code. 0 means success, while 1 means comparison
found a material slowdown.
Raises:
SystemExit: Raised by argparse for invalid arguments.
ValueError: Propagated for invalid or incompatible benchmark data.
FileNotFoundError: Propagated for missing test or artifact files.
RuntimeError: Propagated when a benchmark trial fails.
OSError: Propagated for subprocess or artifact I/O failures.
json.JSONDecodeError: Propagated for malformed benchmark JSON.
Return execution-policy variables used by a benchmark trial.
Args: None.
Returns: Environment values that intentionally may differ between benchmark candidates, such as workspace caps and process-memory limits.
Raises: No deliberate exceptions are raised.