simplebench.reporters.reporter.reporter moduleπ
Reporter base class.
This module defines the Reporter abstract base class, which serves as the foundation for all reporter implementations in the SimpleBench benchmarking framework.
It handles common functionality such as validating input arguments, configuring argparse CLI arguments, managing default options, sending reports to various targets, and orchestrating report generation.
To create a new reporter, a developer must subclass Reporter and implement the abstract render() method. For most reporters, the default run_report() implementation, which renders a report for each section, is sufficient.
A Reporter is responsible for generating reports based on benchmark results from a Session and Case. Reporters can produce reports in various formats and output them to different targets.
- class simplebench.reporters.reporter.reporter.Reporter(
- config: ReporterConfig,
Bases:
ABC,_ReporterArgparseMixin,_ReporterOrchestrationMixin,_ReporterPrioritizationMixin,_ReporterTargetMixin,ReporterProtocolBase class for Reporter classes.
A
Reporteris responsible for generating reports based on benchmark results from aSessionandCase. Reporters can produce reports in various formats and output them to different targets.All
Reportersubclasses must implement the methods defined in this interface. Reporters should handle their own output, whether to console, file system, HTTP endpoint, display device, via a callback or other output.The
Reporterinterface ensures that all reporters provide a consistent set of functionalities, making it easier to manage and utilize differentreporting options within the SimpleBench framework.
Initialize the Reporter instance.
- Parameters:
config (ReporterConfig) β The configuration object for the reporter.
- Raises:
SimpleBenchTypeError β If the provided config is not a ReporterConfig instance.
- add_choice(choice: None) None[source]π
Add a
Choiceto the reporterβs choices.- Parameters:
- Raises:
SimpleBenchTypeError β If the provided choice is not a
Choiceinstance.SimpleBenchValueError β If the choiceβs sections, targets, or formats are not supported by the reporter.
- property choices: Choicesπ
The
Choicesfor the reporter.The
Choicesinstance contains one or moreChoiceinstances, each representing a specific combination of sections, targets, and formats, command line flags, and descriptions.This property allows access to the reporterβs choices for generating reports and customizing report output and available options.
- property config: ReporterConfigπ
The configuration object for the reporter.
- static find_options_by_type(
- options: Iterable[ReporterOptions] | None,
- cls: type[T],
Retrieve an instance of type
cls(if present) from a collection ofReporterOptions.This is used to extract reporter specific options from an iterable container of generic
ReporterOptionssuch as those associated with aChoiceorCase.For example, a
CSVReportermay define aCSVReporterOptionsclass that extendsReporterOptionsand use this method to extract theCSVReporterOptionsinstance from the options iterable:options = Reporter.find_options_by_type(case.options, CSVReporterOptions)
- Parameters:
options (Iterable[
ReporterOptions]) β An iterable ofReporterOptionsinstances.cls (type[T]) β The specific subclass type of
ReporterOptionsto find.
- Returns:
The instance of the class
clsif found, otherwiseNone.- Return type:
T | None
- get_all_stats_values( ) list[float][source]π
Gathers all primary statistical values for a given section across multiple results.
It collects mean, median, minimum, maximum, 5th percentile, and 95th percentile, from each
Resultsinstance for the specified section.This method is useful in determining appropriate scaling factors or units for reporting by analyzing the range of values across all results.
Adjusted standard deviation is not included in this collection because it can be
NaNfor results with insufficient data points, or orders of magnitude different from the other statistics, which can skew scaling calculations.
- get_base_unit_for_section(
- section: Section,
Return the base unit for the specified section.
- classmethod get_default_options() ReporterOptions[source]π
Get the default options for the reporter.
Returns the default options set via
set_default_options()if set, otherwise returns the built-in hardcoded default options fromget_hardcoded_default_options().- Returns:
The default options.
- Return type:
- classmethod get_hardcoded_default_options() Any[source]π
Get the built-in hardcoded default options for the reporter.
This abstract method must be implemented by all
Reportersubclasses. It defines the base class default options for a reporter and must be available in allReportersubclasses.It returns the hardcoded default
ReporterOptionssub-class instance specific to the reporter.Sub-classes must implement the following class variables:
_OPTIONS_TYPE: ClassVar[type[MyOptions]] = MyOptions _OPTIONS_KWARGS: ClassVar[dict[str, Any]] = {β¦}
or the method will raise an exception.
- Returns:
The built-in hardcoded default
ReporterOptionsinstance.- Raises:
SimpleBenchNotImplementedError β If required class variables are not implemented or are of incorrect types.
- property options_type: type[ReporterOptions]π
The specific
ReporterOptionssubclass associated with this reporter.
- abstract render(
- *,
- case: Case,
- section: Section,
- options: ReporterOptions,
Render the report for a specific case and section.
This abstract method must be implemented by all
Reportersubclasses. It is responsible for generating the actual report content for a given case and section, based on the provided options.The output can be a string, bytes, or a Rich object (
TextorTable).- Parameters:
case (
Case) β TheCaseinstance containing the benchmark results.section (
Section) β The specificSectionof the results to render.options (
ReporterOptions) β The reporter-specificReporterOptionsfor rendering.
- Returns:
The rendered report content.
- Return type:
- Raises:
NotImplementedError β If the method is not implemented in a subclass.
- report(
- *,
- log_metadata: ReportLogMetadata,
- args: Namespace,
- case: Case,
- choice: Choice,
- path: Path | None = None,
- session: Session | None = None,
- callback: ReporterCallback | None = None,
Generate a report based on the benchmark results.
This method performs validation and then calls the subclassβs
run_report()method.- Parameters:
log_metadata (
ReportLogMetadata) β The metadata for the report log.args (
Namespace) β The parsed command-line arguments.case (
Case) β TheCaseinstance containing benchmark results.choice (
Choice) β TheChoiceinstance specifying the report configuration.path (
Path| None, optional) β The path to the directory where the report can be saved if needed. Leave asNoneif not saving to the filesystem. Defaults toNone.session (
Session| None, optional) β TheSessioninstance containing benchmark results. Defaults toNone.callback (
ReporterCallback| None, optional) β A callback function for additional processing of the report. Defaults toNone.
- run_report(
- *,
- args: Namespace,
- log_metadata: ReportLogMetadata,
- case: Case,
- choice: Choice,
- path: Path | None = None,
- session: Session | None = None,
- callback: ReporterCallback | None = None,
Orchestration hook for report generation.
This method is the primary customization point for controlling how a report is generated. It is called by the public
report()method after all inputs have been validated.The default implementation calls
render_by_section(), which is suitable for most reporters. Subclasses can override this method to provide alternative orchestration, such as callingrender_by_case()for reports that are generated once per case.Note
This is also the correct place to implement custom logic for non-standard targets like
CUSTOM.- Parameters:
args (
Namespace) β The parsed command-line arguments.log_metadata (:class:`~simplebench.reporters.log.report_log_metadata.Report) β The metadata for the report log.
case (
Case) β TheCaseinstance representing the benchmarked code.choice (
Choice) β TheChoiceinstance specifying the report configuration.path (
Path| None, optional) β The path to the directory where report files will be saved. Defaults toNone.session (
Session| None, optional) β TheSessioninstance containing benchmark results. Defaults toNone.callback (
ReporterCallback| None, optional) β A callback function for additional processing. Defaults toNone.
- classmethod set_default_options(
- options: ReporterOptions | None = None,
Set the default options for the reporter.
- Parameters:
options (
ReporterOptionsor None, optional) β The options to set as the default, defaults to None
- supported_formats() frozenset[Format][source]π
The set of supported
Formatfor the reporter.This is the set of
Formatthat the reporter can output in.Defined
Choicecan only includeFormatthat are declared in this set.
- simplebench.reporters.reporter.reporter.deferred_core_imports() None[source]π
Deferred import of core types to avoid circular imports during initialization.
This imports
Choicewhen needed at runtime, preventing circular import issues during module load time while still allowing its use in creatingChoiceinstances fromChoiceConfinstances.