simplebench.reporters.json.reporter packageπ
JSON Reporter package for simplebench.
- class simplebench.reporters.json.reporter.JSONConfig(
- *,
- name: str | None = None,
- description: str | None = None,
- sections: Iterable[Section] | None = None,
- targets: Iterable[Target] | None = None,
- default_targets: Iterable[Target] | None = None,
- formats: Iterable[Format] | None = None,
- choices: ChoicesConf | None = None,
- file_suffix: str | None = None,
- file_unique: bool | None = None,
- file_append: bool | None = None,
- subdir: str | None = None,
Bases:
ReporterConfigConfiguration for a JSONReporter.
This class inherits from
ReporterConfigand provides a type-safe, discoverable interface for overriding the default settings of aJSONReporter.
- class simplebench.reporters.json.reporter.JSONOptions(*, full_data: bool = False)[source]π
Bases:
ReporterOptionsClass for holding JSON reporter specific options in a Choice or Case.
This class provides additional configuration options specific to the JSON reporter. It is accessed via the
optionsattribute of aChoiceorCaseinstance.- Variables:
full_data (bool) β Whether to include full data in the JSON output.
- class simplebench.reporters.json.reporter.JSONReporter(
- config: JSONConfig | None = None,
Bases:
ReporterClass for outputting benchmark results to JSON files.
It supports reporting statistics for various sections, either separately or together, to the filesystem, via a callback function, or to the console in JSON format.
The JSON files are tagged with metadata comments including the case title, description, and units for clarity.
Defined command-line flags:
--json: {filesystem, console, callback}(default=filesystem) Outputs statistical results to JSON.--json-data: {filesystem, console, callback}(default=filesystem) Outputs results to JSON with full data.
Example usage:
program.py --json # Outputs results to JSON files in the filesystem (default). program.py --json filesystem # Outputs results to JSON files in the filesystem. program.py --json console # Outputs results to the console in JSON format. program.py --json callback # Outputs results via a callback function in JSON format. program.py --json filesystem console # Outputs results to both JSON files and the console.
- Variables:
name (str) β The unique identifying name of the reporter.
description (str) β A brief description of the reporter.
choices (Choices) β A collection of
Choicesinstances defining the reporter instance, CLI flags,Choicename, supportedSectionobjects, supported outputTargetobjects, and supported outputFormatobjects for the reporter.targets (set[Target]) β The supported output targets for the reporter.
formats (set[Format]) β The supported output formats for the reporter.
- mean_change( ) float | None[source]π
Compare two Case instances for a given section and return the change as a float ratio.
The float ratio is calculated as
(value2 - value1) / value1, wherevalue1andvalue2are the mean values for the specified section in the first and second cases, respectively.A value of
0.0indicates no change, a positive value indicates an increase, and a negative value indicates a decrease. If either case does not have data for the specified section,Noneis returned. The ratio is limited to 3 significant digits for clarity and to prevent a false sense of precision to the result.If first mean value is
0.0and second mean value is also0.0, the change is defined as0.0. If first mean value is0.0and second mean value is non-zero, the change is defined asNoneto indicate incomparability.- Parameters:
- Returns:
The change between the mean for two cases for the specified section, or
Noneif the section is not present in either case or the numbers are incomparable.
- render(
- *,
- case: Case,
- section: Section,
- options: ReporterOptions,
Convert the Case data for all sections to a JSON string.
Machine info is included in the JSON output under the βmetadataβ key.
- Parameters:
case β The
Caseinstance holding the benchmarked code statistics.section β The
Sectionto render (ignored, all sections are included).options β The
JSONOptionsinstance specifying rendering options orNoneif not provided. (JSONOptionsis a subclass ofReporterOptions.)
- Returns:
The JSON string representation of the
Casedata.
- run_report(
- *,
- args: Namespace,
- case: Case,
- choice: Choice,
- path: Path | None = None,
- session: Session | None = None,
- callback: ReporterCallback | None = None,
Output the benchmark results to a file as tagged JSON if available.
This method is called by the base classβs
report()method after validation. The base class handles validation of the arguments, so subclasses can assume the arguments are valid without a large amount of boilerplate code. The base class also handles lazy loading of the reporter classes, so subclasses can assume any required imports are available.The
run_report()methodβs main responsibilities are to select the appropriate output method (render_by_case()in this case) based on the provided arguments and to pass the actual rendering method to be used (therender()method in this case). The rendering method must conform with theReportRendererprotocol.- Parameters:
args β The parsed command-line arguments.
case β The
Caseinstance representing the benchmarked code.choice β The
Choiceinstance specifying the report configuration.path β The path to the directory where the JSON file(s) will be saved.
session β The
Sessioninstance containing benchmark results.callback β A callback function for additional processing of the report. The function should accept two arguments: the
Caseinstance and the JSON data as a string. Leave asNoneif no callback is needed.