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,
Bases:
objectContainer 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
Caseto the Sequence of Cases for this session.- Parameters:
- Raises:
SimpleBenchTypeError β If the value is not a
Caseinstance.
- 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
ArgumentParserflags 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
ArgumentParserbefore 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 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( ) 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.
- parse_args( ) 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
argsproperty. By default, it parses the arguments fromsys.argv. Ifargsis 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_parseris not set.
- property progress: Progressπ
The Rich Progress instance for displaying progress bars.
- 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.
- property reporter_manager: ReporterManagerπ
Return the
ReporterManagerinstance for managing reporters.- Returns:
The
ReporterManagerinstance for managing reporters.- Return type:
- property tasks: RichProgressTasksπ
The RichProgressTasks instance for managing progress tasks.