scenarioBenchmarkNumba
Benchmark attitude-control scenarios across C++, Python, and Numba implementations.
- This script measures two key timings for each simulation run:
init – InitializeSimulation (one-time setup; includes Numba cache load) exec – ExecuteSimulation (steady-state runtime cost)
The minimum timing is used as the primary performance metric because it best approximates achievable throughput with minimal OS scheduling noise.
- Two scenario groups are evaluated:
- Pointing:
Compare a single control module implemented in C++, Python, and Numba.
- Feedback:
Compare full FSW + sensor stacks implemented in C++ vs Numba.
- class scenarioBenchmarkNumba.BenchmarkResult(label: str, init: TimingStats, exec: TimingStats)[source]
Bases:
objectStores timing statistics for a single benchmark configuration.
- class scenarioBenchmarkNumba.Scenario(label: str, run: Callable[[], Any])[source]
Bases:
objectRepresents a benchmarkable simulation scenario.
- label
Human-readable name for reporting.
- Type:
str
- run
Callable that executes the scenario once.
- Type:
Callable[[], Any]
- class scenarioBenchmarkNumba.TimingStats(min: float, median: float, max: float, stdev: float)[source]
Bases:
objectContainer for summary statistics of a timing sample.
- scenarioBenchmarkNumba.computeStats(samples: list[float]) TimingStats[source]
Compute descriptive statistics for a list of timing samples.
- Parameters:
samples – List of timing measurements.
- Returns:
TimingStats object containing min, median, max, and stdev.
- Raises:
ValueError – If the input list is empty.
- scenarioBenchmarkNumba.formatSeconds(seconds: float) str[source]
Format a duration using adaptive time units.
- Parameters:
seconds – Duration in seconds.
- Returns:
Formatted duration string.
- scenarioBenchmarkNumba.measureScenario(scenario: Scenario, nRuns: int = 10) BenchmarkResult[source]
Benchmark a scenario over multiple runs.
- Parameters:
scenario – Scenario object containing label and run function.
nRuns – Number of repetitions.
- Returns:
BenchmarkResult containing timing statistics for init and exec.
- scenarioBenchmarkNumba.patchedSimTimers()[source]
Context manager that patches simulation methods to measure execution time.
- Temporarily replaces:
InitializeSimulation
ExecuteSimulation
to capture timing information for each run.
- Yields:
dict – Mutable dictionary with keys ‘init’ and ‘exec’ storing durations.
- Guarantees:
Original methods are restored after exiting the context.
- scenarioBenchmarkNumba.printResultsTable(results: list[BenchmarkResult], title: str, labelCol: int = 28) None[source]
Print a single compact benchmark table for one scenario family.
- Parameters:
results – Benchmark results to print.
title – Title of the scenario family.
labelCol – Width of the label column.
- scenarioBenchmarkNumba.run(case: Literal['pointing', 'feedback'] = 'feedback', nRuns: int = 10) None[source]
Main scenario entry point