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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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)
adjusted_standard_deviation (float) β The standard deviation adjusted for the number of rounds. (read only)
relative_standard_deviation (float) β The relative standard deviation of ops per time interval. (read only)
adjusted_relative_standard_deviation (float) β The adjusted relative standard deviation of ops per time interval. (read only)
percentiles (tuple[float, ...]) β Percentiles of operations per time interval. (read only)
- property adjusted_relative_standard_deviation: floatπ
The adjusted relative standard deviation of the data.
- property adjusted_standard_deviation: floatπ
The standard deviation adjusted for the number of rounds.
This metric βun-suppressesβ the variability that is reduced by averaging across multiple rounds. It is calculated by multiplying the standard deviation by the square root of the number of rounds.
- 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)
- property adjusted_relative_standard_deviation: floatπ
The adjusted relative standard deviation of the data.
- property adjusted_standard_deviation: floatπ
The standard deviation adjusted for the number of rounds.
- 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
StatsStats.adjusted_relative_standard_deviationStats.adjusted_standard_deviationStats.as_dictStats.dataStats.from_dict()Stats.maximumStats.meanStats.medianStats.minimumStats.percentilesStats.relative_standard_deviationStats.roundsStats.scaleStats.standard_deviationStats.stats_summaryStats.unit
StatsSummaryStatsSummary.adjusted_relative_standard_deviationStatsSummary.adjusted_standard_deviationStatsSummary.as_dictStatsSummary.dataStatsSummary.from_dict()StatsSummary.from_stats()StatsSummary.maximumStatsSummary.meanStatsSummary.medianStatsSummary.minimumStatsSummary.percentilesStatsSummary.relative_standard_deviationStatsSummary.roundsStatsSummary.scaleStatsSummary.standard_deviationStatsSummary.unit