simplebench.stats packageπ
Stats module for SimpleBench benchmarking framework.
- class simplebench.stats.MemoryUsage(
- *,
- iterations: Sequence[Iteration] | None = None,
- unit: str = 'bytes',
- scale: float = 1.0,
- rounds: int = 1,
- data: Sequence[int | float] | None = None,
Bases:
StatsContainer for the memory usage statistics of a benchmark.
- Variables:
unit (str) β The unit of measurement for the memory usage (e.g., βMBβ).
scale (float) β The scale factor for the memory usage (e.g., β1e6β for megabytes).
rounds (int) β The number of data points in the benchmark.
data (tuple[float | int, ...]) β Tuple of memory usage data points.
mean (float) β The mean memory usage.
median (float) β The median memory usage.
minimum (float) β The minimum memory usage.
maximum (float) β The maximum memory usage.
standard_deviation (float) β The standard deviation of the memory usage.
relative_standard_deviation (float) β The relative standard deviation of the memory usage.
percentiles (dict[int, float]) β Percentiles of memory usage.
Construct MemoryUsage stats from sequence of Iteration or raw memory data.
At least one of
iterationsordatamust be provided.If provided,
iterationsmust be a sequence ofIterationobjects and memory data will be extracted from eachmemoryattribute. Ifdatais also provided, the memory data extracted from the iterations will be appended to the provided data.- Parameters:
iterations β Optional list of
Iterationobjects to extract memory data from.unit β Optional unit of measurement for the memory usage (e.g., βMBβ). Defaults to βbytesβ.
scale β Optional scale factor for the memory usage (e.g., β1e6β for megabytes). Defaults to 1.0.
rounds β The number of data points in the benchmark. Defaults to 1.
data β Optional list of memory usage data points. If not provided, memory data will be extracted from the iterations if available.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.MemoryUsageSummary(
- *,
- unit: str,
- scale: float,
- rounds: int,
- mean: float,
- median: float,
- minimum: float,
- maximum: float,
- standard_deviation: float,
- relative_standard_deviation: float,
- percentiles: tuple[float, ...],
Bases:
StatsSummaryContainer for summary statistics of a MemoryUsage benchmark.
This class is exclusive of raw data points.
- Variables:
unit (str) β The unit of measurement for the benchmark (e.g., βops/sβ).
scale (float) β The scale factor for the interval (e.g. 1 for seconds).
rounds (int) β The number of data points in the benchmark.
data (tuple[int | float, ...]) β Always an empty tuple as a
StatsSummaryobject does not contain raw data points.mean (float) β The mean operations per time interval.
median (float) β The median operations per time interval.
minimum (float) β The minimum operations per time interval.
maximum (float) β The maximum operations per time interval.
standard_deviation (float) β The standard deviation of operations per time interval.
relative_standard_deviation (float) β The relative standard deviation of ops per time interval.
percentiles (tuple[float, ...]) β Percentiles of operations per time interval.
Initialize the StatsSummary object.
- Parameters:
unit (str) β The unit of measurement for the data (e.g., βops/sβ).
scale (float) β The scale factor the data (e.g. 1.0 for seconds).
rounds (int) β The number of rounds each data point represents.
mean (float) β The mean data point.
median (float) β The median data point.
minimum (float) β The minimum data point.
maximum (float) β The maximum data point.
standard_deviation (float) β The standard deviation of data.
relative_standard_deviation (float) β The relative standard deviation of data.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.OperationTimings(
- *,
- iterations: Sequence[Iteration] | None = None,
- unit: str = 'ns',
- scale: float = 1e-09,
- rounds: int = 1,
- data: Sequence[int | float] | None = None,
Bases:
StatsContainer for the operation timing statistics of a benchmark.
- Variables:
unit (str) β The unit of measurement for the timings (e.g., βnsβ).
scale (float) β The scale factor for the timings (e.g., β1e-9β for nanoseconds).
rounds (int) β The number of data points in the benchmark.
data (tuple[int | float, ...]) β Tuple of timing data points.
mean (float) β The mean time per operation.
median (float) β The median time per operation.
minimum (float) β The minimum time per operation.
maximum (float) β The maximum time per operation.
standard_deviation (float) β The standard deviation of the time per operation.
relative_standard_deviation (float) β The relative standard deviation of the time per operation.
percentiles (dict[int, float]) β Percentiles of time per operation.
Construct OperationTimings stats from Iteration or raw timing data.
- Parameters:
iterations β Sequence of
Iterationobjects to extract timing data from.unit β The unit of measurement for the timings (e.g., βnsβ).
scale β The scale factor for the timings (e.g., β1e-9β for nanoseconds).
rounds β The number of data points in the benchmark.
data β Optional sequence of timing data points. If not provided, timing data will be extracted from the iterations if available.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.OperationTimingsSummary(
- *,
- unit: str,
- scale: float,
- rounds: int,
- mean: float,
- median: float,
- minimum: float,
- maximum: float,
- standard_deviation: float,
- relative_standard_deviation: float,
- percentiles: tuple[float, ...],
Bases:
StatsSummaryContainer for summary of operation timing statistics of a benchmark.
- Variables:
unit (str) β The unit of measurement for the benchmark (e.g., βops/sβ).
scale (float) β The scale factor for the interval (e.g. 1 for seconds).
rounds (int) β The number of data points in the benchmark.
mean (float) β The mean operations per time interval.
median (float) β The median operations per time interval.
minimum (float) β The minimum operations per time interval.
maximum (float) β The maximum operations per time interval.
standard_deviation (float) β The standard deviation of operations per time interval.
relative_standard_deviation (float) β The relative standard deviation of ops per time interval.
percentiles (dict[int, float]) β Percentiles of operations per time interval.
Initialize the StatsSummary object.
- Parameters:
unit (str) β The unit of measurement for the data (e.g., βops/sβ).
scale (float) β The scale factor the data (e.g. 1.0 for seconds).
rounds (int) β The number of rounds each data point represents.
mean (float) β The mean data point.
median (float) β The median data point.
minimum (float) β The minimum data point.
maximum (float) β The maximum data point.
standard_deviation (float) β The standard deviation of data.
relative_standard_deviation (float) β The relative standard deviation of data.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.OperationsPerInterval(
- *,
- iterations: Sequence[Iteration] | None = None,
- unit: str = 'Ops/s',
- scale: float = 1.0,
- rounds: int = 1,
- data: Sequence[int | float] | None = None,
Bases:
StatsContainer for the operations per time interval statistics of a benchmark.
- Variables:
unit (str) β The unit of measurement for the benchmark (e.g., βops/sβ).
scale (float) β The scale factor for the interval (e.g. 1 for seconds).
rounds (int) β The number of data points in the benchmark.
mean (float) β The mean operations per time interval.
median (float) β The median operations per time interval.
minimum (float) β The minimum operations per time interval.
maximum (float) β The maximum operations per time interval.
standard_deviation (float) β The standard deviation of operations per time interval.
relative_standard_deviation (float) β The relative standard deviation of ops per time interval.
percentiles (dict[int, float]) β Percentiles of operations per time interval.
Construct OperationsPerInterval stats from Iteration or raw ops data.
- Parameters:
iterations β List of
Iterationobjects to extract ops data from.unit β The unit of measurement for the benchmark (e.g., βops/sβ).
scale β The scale factor for the interval (e.g. 1 for seconds).
rounds β The number of data points in the benchmark.
data β Optional list of ops data points. If not provided, ops data will be extracted from the iterations if available.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.OperationsPerIntervalSummary(
- *,
- unit: str,
- scale: float,
- rounds: int,
- mean: float,
- median: float,
- minimum: float,
- maximum: float,
- standard_deviation: float,
- relative_standard_deviation: float,
- percentiles: tuple[float, ...],
Bases:
StatsSummarySummary of OperationsPerInterval statistics.
- Variables:
unit (str) β The unit of measurement for the benchmark (e.g., βops/sβ).
scale (float) β The scale factor for the interval (e.g. 1 for seconds).
rounds (int) β The number of data points in the benchmark.
mean (float) β The mean operations per time interval.
median (float) β The median operations per time interval.
minimum (float) β The minimum operations per time interval.
maximum (float) β The maximum operations per time interval.
standard_deviation (float) β The standard deviation of operations per time interval.
relative_standard_deviation (float) β The relative standard deviation of ops per time interval.
percentiles (dict[int, float]) β Percentiles of operations per time interval.
Initialize the StatsSummary object.
- Parameters:
unit (str) β The unit of measurement for the data (e.g., βops/sβ).
scale (float) β The scale factor the data (e.g. 1.0 for seconds).
rounds (int) β The number of rounds each data point represents.
mean (float) β The mean data point.
median (float) β The median data point.
minimum (float) β The minimum data point.
maximum (float) β The maximum data point.
standard_deviation (float) β The standard deviation of data.
relative_standard_deviation (float) β The relative standard deviation of data.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.PeakMemoryUsage(
- *,
- iterations: Sequence[Iteration] | None = None,
- unit: str = 'bytes',
- scale: float = 1.0,
- rounds: int = 1,
- data: Sequence[int | float] | None = None,
Bases:
StatsContainer for the peak memory usage statistics of a benchmark.
- Variables:
unit (str) β The unit of measurement for the memory usage (e.g., βMBβ).
scale (float) β The scale factor for the memory usage (e.g., β1e6β for megabytes).
rounds (int) β The number of data points in the benchmark.
data (tuple[int | float, ...]) β Tuple of peak memory usage data points.
mean (float) β The mean memory usage.
median (float) β The median memory usage.
minimum (float) β The minimum memory usage.
maximum (float) β The maximum memory usage.
standard_deviation (float) β The standard deviation of the memory usage.
relative_standard_deviation (float) β The relative standard deviation of the memory usage.
percentiles (dict[int, float]) β Percentiles of memory usage.
Construct PeakMemoryUsage stats from Iteration or raw memory data.
- Parameters:
iterations β Sequence of
Iterationobjects to extract peak memory data from.unit β The unit of measurement for the memory usage (e.g., βMBβ).
scale β The scale factor for the memory usage (e.g., β1e6β for megabytes).
rounds β The number of data points in the benchmark.
data β Optional Sequence of peak memory usage data points. If not provided, peak memory data will be extracted from the iterations if available.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.PeakMemoryUsageSummary(
- *,
- unit: str,
- scale: float,
- rounds: int,
- mean: float,
- median: float,
- minimum: float,
- maximum: float,
- standard_deviation: float,
- relative_standard_deviation: float,
- percentiles: tuple[float, ...],
Bases:
StatsSummaryContainer for the summary of peak memory usage statistics of a benchmark.
- Variables:
unit (str) β The unit of measurement for the memory usage (e.g., βMBβ).
scale (float) β The scale factor for the memory usage (e.g., β1e6β for megabytes).
rounds (int) β The number of data points in the benchmark.
mean (float) β The mean memory usage.
median (float) β The median memory usage.
minimum (float) β The minimum memory usage.
maximum (float) β The maximum memory usage.
standard_deviation (float) β The standard deviation of the memory usage.
relative_standard_deviation (float) β The relative standard deviation of the memory usage.
percentiles (dict[int, float]) β Percentiles of memory usage.
Initialize the StatsSummary object.
- Parameters:
unit (str) β The unit of measurement for the data (e.g., βops/sβ).
scale (float) β The scale factor the data (e.g. 1.0 for seconds).
rounds (int) β The number of rounds each data point represents.
mean (float) β The mean data point.
median (float) β The median data point.
minimum (float) β The minimum data point.
maximum (float) β The maximum data point.
standard_deviation (float) β The standard deviation of data.
relative_standard_deviation (float) β The relative standard deviation of data.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- class simplebench.stats.Stats( )[source]π
Bases:
objectGeneric container for statistics on a benchmark.
- Variables:
unit (str) β The unit of measurement for the benchmark (e.g., βops/sβ). (read only)
scale (float) β The scale factor for the interval (e.g. 1 for seconds). (read only)
rounds (int) β The number of rounds each data point represents. (read only)
data (tuple[float | int, ...]) β Tuple of data points. (read only)
mean (float) β The mean operations per time interval. (read only)
median (float) β The median operations per time interval. (read only)
minimum (float) β The minimum operations per time interval. (read only)
maximum (float) β The maximum operations per time interval. (read only)
standard_deviation (float) β The standard deviation of operations per time interval. (read only)
relative_standard_deviation (float) β The relative standard deviation of ops per time interval. (read only)
percentiles (tuple[float, ...]) β Percentiles of operations per time interval. (read only)
Initialize the Stats object.
- Parameters:
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- property as_dict: dict[str, str | float | dict[int, float] | tuple[int | float, ...]]π
Returns the statistics and data as a JSON-serializable dictionary.
This includes all the statistics as well as the raw data points.
The data values are scaled according to the scale factor to provide human-readable values using the base unit rather than the scaled unit.
The unit is normalized to its SI base unit representation. (e.g., βmsβ becomes βsβ)
The dictionary is mutability-safe as all data is either a primitive or a copy.
- Returns:
A dictionary containing the statistics and the scaled data points.
- classmethod from_dict( ) Stats[source]π
Construct a Stats object from a dictionary.
Example
stats_dict = { "unit": "ops/s", "scale": 1, "data": [1000, 2000, 1500, 3000, 2500] } stats = Stats.from_dict(stats_dict) print(stats.mean) # Output: 2000.0
- Parameters:
data (dict) β A dictionary containing the stats data. Must contain βdataβ key with a non-empty sequence of data points consisting of integers or floats.
- Returns:
A Stats object constructed from the provided dictionary.
- Raises:
SimpleBenchTypeError β If the data, unit, or scale arguments are of the wrong type.
SimpleBenchKeyError β If the data dictionary does not contain a βunitβ key and no unit argument is provided.
SimpleBenchValueError β If the data dictionary does not contain a non-empty βdataβ key with at least one data point, if the scale argument is not greater than zero, or if the unit argument is an empty string
- property percentiles: tuple[float, ...]π
Percentiles of the data.
Returns the 0th through 100th percentiles of the data as an immutable tuple.
- property stats_summary: StatsSummaryπ
Returns a StatsSummary object created from this Stats object.
- Returns:
A StatsSummary object containing the same statistics as this Stats object.
- class simplebench.stats.StatsSummary(
- *,
- unit: str,
- scale: float,
- rounds: int,
- mean: float,
- median: float,
- minimum: float,
- maximum: float,
- standard_deviation: float,
- relative_standard_deviation: float,
- percentiles: tuple[float, ...],
Bases:
objectContainer for summary statistics of a benchmark, exclusive of raw data points.
This is a lightweight, data-only version of the Stats class, suitable for serialization or reporting when raw data points are not needed.
- Variables:
unit (str) β The unit of measurement for the benchmark (e.g., βops/sβ). (read only)
scale (float) β The scale factor for the interval (e.g. 1 for seconds). (read only)
rounds (int) β The number of rounds each data point represents. (read only)
mean (float) β The mean operations per time interval. (read only)
median (float) β The median operations per time interval. (read only)
minimum (float) β The minimum operations per time interval. (read only)
maximum (float) β The maximum operations per time interval. (read only)
standard_deviation (float) β The standard deviation of operations per time interval. (read only)
relative_standard_deviation (float) β The relative standard deviation of ops per time interval. (read only)
percentiles (tuple[float, ...]) β Percentiles of operations per time interval. (read only)
data (tuple[int | float, ...]) β Always an empty tuple as StatsSummary does not contain raw data points. (read only)
Initialize the StatsSummary object.
- Parameters:
unit (str) β The unit of measurement for the data (e.g., βops/sβ).
scale (float) β The scale factor the data (e.g. 1.0 for seconds).
rounds (int) β The number of rounds each data point represents.
mean (float) β The mean data point.
median (float) β The median data point.
minimum (float) β The minimum data point.
maximum (float) β The maximum data point.
standard_deviation (float) β The standard deviation of data.
relative_standard_deviation (float) β The relative standard deviation of data.
- Raises:
SimpleBenchTypeError β If any of the arguments are of the wrong type.
SimpleBenchValueError β If any of the arguments have invalid values.
- property as_dict: dict[str, str | float | dict[int, float] | tuple[int | float, ...]]π
Returns the statistics as a JSON-serializable dictionary.
The data values are scaled according to the scale factor to provide human-readable values using the base unit rather than the scaled unit.
The unit is converted to its SI base unit representation. (e.g., βmsβ becomes βsβ)
This does not include raw data points, only the statistics.
The dictionary is mutability-safe as all data is either a primitive or a copy.
- Returns:
A dictionary containing the statistics.
- property data: tuple[int | float, ...]π
The data points.
This is always an empty tuple as a StatsSummary does not contain raw data points.
- classmethod from_dict( ) StatsSummary[source]π
Construct a StatsSummary object from a dictionary.
Example
stats_summary_dict = { "unit": "ops/s", "scale": 1.0, "rounds": 1, "mean": 2000.0, "median": 2000.0, "minimum": 1000.0, "maximum": 3000.0, "standard_deviation": 790.5694150420949, "relative_standard_deviation": 39.52847075252201, "percentiles": [1000.0, 1300.0, 1600.0, 1900.0, 2200.0, 2500.0, 2800.0, 3000.0, 3000.0] } stats_summary = StatsSummary.from_dict(stats_summary_dict) print(stats_summary.mean) # Output: 2000.0
- Parameters:
data (dict) β A dictionary containing the stats data. Must contain βdataβ key with a non-empty sequence of data points consisting of integers or floats.
- Returns:
A StatsSummary object constructed from the provided dictionary.
- Raises:
SimpleBenchTypeError β If the data, unit, or scale arguments are of the wrong type.
SimpleBenchKeyError β If the data dictionary does not contain a βunitβ key and no unit argument is provided.
SimpleBenchValueError β If the data dictionary does not contain a non-empty βdataβ key with at least one data point, if the scale argument is not greater than zero, or if the unit argument is an empty string
- classmethod from_stats(
- stats: Stats,
Construct a new StatsSummary object from a Stats object.
- Parameters:
stats (Stats) β The Stats object to derive the summary from.
- Returns:
A new StatsSummary object containing the same statistics as the provided Stats object.
- Raises:
SimpleBenchTypeError β If the stats argument is not a Stats object.
Subpackagesπ
Submodulesπ
- simplebench.stats.memory_usage module
- simplebench.stats.operation_timings module
- simplebench.stats.operations_per_interval module
- simplebench.stats.peak_memory_usage module
- simplebench.stats.stats module
StatsStatsSummaryStatsSummary.as_dictStatsSummary.dataStatsSummary.from_dict()StatsSummary.from_stats()StatsSummary.maximumStatsSummary.meanStatsSummary.medianStatsSummary.minimumStatsSummary.percentilesStatsSummary.relative_standard_deviationStatsSummary.roundsStatsSummary.scaleStatsSummary.standard_deviationStatsSummary.unit