simplebench.session moduleπŸ”—

Session management for SimpleBench.

class simplebench.session.Session(
*,
cases: Sequence[Case] | None = None,
verbosity: Verbosity = Verbosity.NORMAL,
default_runner: type[SimpleRunner] | None = None,
args_parser: ArgumentParser | None = None,
progress: bool = False,
output_path: Path | None = None,
console: Console | None = None,
)[source]πŸ”—

Bases: object

Container for session related information while running benchmarks.

Variables:
  • args (Namespace) – The command line arguments for the session.

  • cases (Sequence[Case]) – Sequence of benchmark cases for the session.

  • output_path (Path, optional) – The output path for reports.

  • console (Console) – A Rich Console instance for displaying output.

  • verbosity (Verbosity) – Verbosity level for console output (default: Verbosity.NORMAL)

  • default_runner (type[SimpleRunner]) – The default runner class to use for Cases that do not specify a runner. Defaults to SimpleRunner.

  • show_progress (bool) – Whether to show progress bars during execution. Defaults to False.

  • progress (Progress) – Rich Progress instance for displaying progress bars. (read only)

  • tasks (RichProgressTasks) – The ProgressTasks instance for managing progress tasks. (read only)

  • reporter_manager (ReporterManager) – The ReporterManager instance for managing reporters. (read only)

add(case: Case) None[source]πŸ”—

Add a Case to the Sequence of Cases for this session.

Parameters:

case (Case) – Case to add to the Session

Raises:

SimpleBenchTypeError – If the value is not a Case instance.

add_reporter_flags() None[source]πŸ”—

Add the command line flags for all registered reporters to the session’s ArgumentParser.

Any conflicts in flag names with already declared ArgumentParser flags will have to be handled by the reporters themselves.

This method should be called before parse_args().

It is placed in its own method so that a user can customize the ArgumentParser before or after adding the reporter flags as needed.

It also allows the user to unregister reporters before adding the reporter flags if they want to omit specific built-in reporters entirely.

Raises:

SimpleBenchArgumentError – If there is a conflict or other error in reporter flag names.

property args: Namespace | NoneπŸ”—

The command line arguments for the session. This will be None until the parse_args() method has been called.

property args_parser: ArgumentParserπŸ”—

The ArgumentParser instance for the session.

property cases: Sequence[Case]πŸ”—

Sequence of Cases for this session.

property console: ConsoleπŸ”—

The Rich Console instance for displaying output.

property default_runner: type[SimpleRunner] | NoneπŸ”—

The session scoped default runner class to use for Cases that do not specify a runner.

extend(
cases: Sequence[Case],
) None[source]πŸ”—

Extend the Sequence of Cases for this session.

Parameters:

cases (Sequence[Case]) – Sequence of Cases to add to the Session

Raises:

SimpleBenchTypeError – If the value is not a Sequence of Cases.

property output_path: Path | NoneπŸ”—

The output path for reports.

parse_args(
args: Sequence[str] | None = None,
) None[source]πŸ”—

Parse the command line arguments using the session’s ArgumentParser.

This method parses the command line arguments and stores them in the session’s args property. By default, it parses the arguments from sys.argv. If args is provided, it will parse the arguments from the provided sequence of strings instead.

Parameters:

args (Sequence[str], optional) – A list of command line arguments to parse. If None, the arguments will be taken from sys.argv. Defaults to None.

Raises:

SimpleBenchTypeError – If the args_parser is not set.

property progress: ProgressπŸ”—

The Rich Progress instance for displaying progress bars.

report() None[source]πŸ”—

Generate reports for all benchmark cases in the session.

report_keys() list[str][source]πŸ”—

Get a list of report keys for all reports to be generated in this session.

This filters the report choices based on the command line arguments that were set and parsed when the session was created and returns a list of report keys for the reports that should be generated.

Returns:

A list of report keys for all reports to be generated in this session.

Return type:

list[str]

property reporter_manager: ReporterManagerπŸ”—

Return the ReporterManager instance for managing reporters.

Returns:

The ReporterManager instance for managing reporters.

Return type:

ReporterManager

run() None[source]πŸ”—

Run all benchmark cases in the session.

property show_progress: boolπŸ”—

Whether to show progress bars during execution.

property tasks: RichProgressTasksπŸ”—

The RichProgressTasks instance for managing progress tasks.

property verbosity: VerbosityπŸ”—

The Verbosity level for this session.