Bench Compare¶
benchmatrix.bench_compare ¶
Matrix-aware comparison of parsed benchmark runs.
RunCompatibilityPolicy
dataclass
¶
Policy controlling run-environment compatibility checks.
permissive keeps lower-risk differences as warnings, strict
promotes every difference or missing environment record to a blocker, and
off disables run-level compatibility checks.
Source code in src/benchmatrix/bench_compare.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
__post_init__ ¶
__post_init__() -> None
Validate the compatibility mode.
Source code in src/benchmatrix/bench_compare.py
75 76 77 78 | |
RunCompatibilityFinding
dataclass
¶
One material difference between two run environments.
Source code in src/benchmatrix/bench_compare.py
81 82 83 84 85 86 87 88 89 90 91 | |
RunCompatibilityReport
dataclass
¶
Compatibility findings for the baseline and candidate environments.
Source code in src/benchmatrix/bench_compare.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
blocking
property
¶
blocking: tuple[RunCompatibilityFinding, ...]
Return differences that prevent a trustworthy comparison.
warnings
property
¶
warnings: tuple[RunCompatibilityFinding, ...]
Return non-blocking environment differences.
is_compatible
property
¶
is_compatible: bool
Return whether no blocking environment differences were found.
EvidencePolicy
dataclass
¶
Minimum evidence required for repeated-run classifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minimum_runs
|
int
|
Minimum files on each side containing a matrix cell. |
5
|
minimum_samples_per_run
|
int
|
Minimum raw timing samples required from each observed file. |
5
|
minimum_rounds_per_run
|
int
|
Minimum pytest-benchmark rounds required from each observed file. |
5
|
require_rounds
|
bool
|
Whether every row must report a positive round count. |
True
|
require_iterations
|
bool
|
Whether every row must report a positive iteration count. |
True
|
require_raw_samples_for_inference
|
bool
|
Whether every observed row must retain raw per-round durations. |
True
|
minimum_tail_samples_per_run
|
int
|
Minimum round-duration observations required from each tail-latency row. |
100
|
require_tail_iterations_one
|
bool
|
Whether tail-latency rows must represent individual calls rather than averages of multiple iterations. |
True
|
maximum_cv
|
float | None
|
Optional maximum within-run coefficient of variation. |
None
|
maximum_outlier_fraction
|
float | None
|
Optional maximum within-run Tukey-outlier fraction. |
None
|
Source code in src/benchmatrix/bench_compare.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
__post_init__ ¶
__post_init__() -> None
Validate evidence thresholds.
Source code in src/benchmatrix/bench_compare.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
BenchmarkEvidence
dataclass
¶
Trust diagnostics for one side of a matrix-cell comparison.
Attributes:
| Name | Type | Description |
|---|---|---|
provided_run_count |
int
|
Files supplied for this side. |
observed_run_count |
int
|
Files containing this matrix cell. |
rounds |
tuple[int | None, ...]
|
Positive pytest-benchmark round counts aligned to the files. |
iterations |
tuple[int | None, ...]
|
Positive iteration counts aligned to the files. |
sample_counts |
tuple[int, ...]
|
Raw timing sample counts aligned to the files. |
sample_count |
int
|
Total pooled raw timing samples. |
iqr |
float | None
|
Interquartile range of pooled timing samples in seconds. Retained as a descriptive compatibility field; evidence gates use the corresponding per-run diagnostics. |
coefficient_of_variation |
float | None
|
Pooled timing-sample population standard deviation divided by the absolute mean. |
outlier_count |
int | None
|
Samples outside the pooled 1.5-IQR Tukey fences. |
outlier_fraction |
float | None
|
Outlier count divided by total sample count. |
adequate |
bool
|
Whether the configured evidence policy was satisfied. |
issues |
tuple[str, ...]
|
Human-readable reasons evidence is inadequate. |
run_iqrs |
tuple[float | None, ...]
|
Per-run timing-sample interquartile ranges. |
run_coefficients_of_variation |
tuple[float | None, ...]
|
Per-run coefficients of variation. |
run_outlier_counts |
tuple[int | None, ...]
|
Per-run Tukey-outlier counts. |
run_outlier_fractions |
tuple[float | None, ...]
|
Per-run Tukey-outlier fractions. |
Source code in src/benchmatrix/bench_compare.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | |
InferencePolicy
dataclass
¶
Policy controlling run-level statistical inference.
The default method bootstraps complete process-run statistics, applies a
BCa interval, and uses a Bonferroni-adjusted simultaneous confidence level
across the reported matrix. legacy_consistency preserves the version 1
observed-pairwise-range decision rule and is intentionally non-inferential.
Source code in src/benchmatrix/bench_compare.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
__post_init__ ¶
__post_init__() -> None
Validate inference controls.
Source code in src/benchmatrix/bench_compare.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | |
PrecisionPolicy
dataclass
¶
Optional fixed-design precision target for paired pilot comparisons.
target_half_width_percent=None disables planning. When enabled, each
paired matrix cell estimates the pair count for a fresh future collection;
the pilot comparison and its pass/fail decision are never changed by the
plan.
Source code in src/benchmatrix/bench_compare.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
__post_init__ ¶
__post_init__() -> None
Validate and normalize the optional percentage target.
Source code in src/benchmatrix/bench_compare.py
296 297 298 299 300 301 302 303 304 305 306 | |
BenchmarkInference
dataclass
¶
Statistical inference for one benchmark matrix cell.
Source code in src/benchmatrix/bench_compare.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
__post_init__ ¶
__post_init__() -> None
Validate and normalize an inference result.
Source code in src/benchmatrix/bench_compare.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
RegressionPolicy
dataclass
¶
Threshold policy for classifying benchmark changes.
Thresholds are percentage points and must be finite and non-negative. More specific mappings override broader ones in this order: exact matrix cell, case, implementation, metric, then the default threshold.
Source code in src/benchmatrix/bench_compare.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
__post_init__ ¶
__post_init__() -> None
Validate thresholds and freeze policy mappings.
Source code in src/benchmatrix/bench_compare.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | |
threshold_for ¶
threshold_for(
implementation_name: str,
case_name: str,
metric_name: MetricName,
) -> float
Return the effective threshold for one matrix cell.
Source code in src/benchmatrix/bench_compare.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 | |
threshold_scope_for ¶
threshold_scope_for(
implementation_name: str,
case_name: str,
metric_name: MetricName,
) -> RegressionThresholdScope
Return the selector scope that supplies one cell's threshold.
Source code in src/benchmatrix/bench_compare.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
BenchmarkComparison
dataclass
¶
Comparison for one implementation, case, and metric matrix cell.
percent_change is the conventional candidate change from baseline,
while improvement_percent is direction-aware and therefore positive
when the candidate is better.
Source code in src/benchmatrix/bench_compare.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 | |
BenchmarkRunComparison
dataclass
¶
Matrix-aware comparison between a baseline and candidate run.
Source code in src/benchmatrix/bench_compare.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
matched
property
¶
matched: tuple[BenchmarkComparison, ...]
Return cells that were compared successfully.
missing
property
¶
missing: tuple[BenchmarkComparison, ...]
Return cells absent from either input run.
incompatible
property
¶
incompatible: tuple[BenchmarkComparison, ...]
Return cells whose measurement context cannot be compared.
improved
property
¶
improved: tuple[BenchmarkComparison, ...]
Return comparable cells that exceeded their improvement threshold.
unchanged
property
¶
unchanged: tuple[BenchmarkComparison, ...]
Return comparable cells whose changes stayed within threshold.
regressed
property
¶
regressed: tuple[BenchmarkComparison, ...]
Return comparable cells that exceeded their regression threshold.
inconclusive
property
¶
inconclusive: tuple[BenchmarkComparison, ...]
Return matched cells whose evidence cannot support a decision.
not_comparable
property
¶
not_comparable: tuple[BenchmarkComparison, ...]
Return cells without a trustworthy regression classification.
is_complete
property
¶
is_complete: bool
Return whether every matrix cell was compared successfully.
is_comparable
property
¶
is_comparable: bool
Return whether environment and every matrix cell are comparable.
has_regressions
property
¶
has_regressions: bool
Return whether any comparable matrix cell regressed.
compare_benchmark_runs ¶
compare_benchmark_runs(
baseline: BenchmarkRun,
candidate: BenchmarkRun,
*,
compatibility_policy: RunCompatibilityPolicy
| None = None,
regression_policy: RegressionPolicy | None = None,
inference_policy: InferencePolicy | None = None,
precision_policy: PrecisionPolicy | None = None,
) -> BenchmarkRunComparison
Compare two runs across the union of their benchmark matrix cells.
Comparisons use mean latency for single_call_latency, mean throughput
for batch_throughput, and p95 latency for tail_latency. Missing
cells and changed case or unit metadata are retained as explicit results
rather than silently dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baseline
|
BenchmarkRun
|
Reference benchmark run. |
required |
candidate
|
BenchmarkRun
|
Benchmark run being evaluated. |
required |
compatibility_policy
|
RunCompatibilityPolicy | None
|
Environment checks to apply. Defaults to permissive compatibility. |
None
|
regression_policy
|
RegressionPolicy | None
|
Thresholds used to classify cell changes. Defaults to a five-percent threshold. |
None
|
inference_policy
|
InferencePolicy | None
|
Run-level uncertainty analysis to apply. A single run cannot produce a default bootstrap interval and is therefore inconclusive unless the legacy method is selected explicitly. |
None
|
precision_policy
|
PrecisionPolicy | None
|
Optional precision planning. Planning requires an explicitly paired design and is rejected for this single-run API. |
None
|
Returns:
| Type | Description |
|---|---|
BenchmarkRunComparison
|
A deterministic comparison across both run matrices. |
Source code in src/benchmatrix/bench_compare.py
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
compare_benchmark_run_groups ¶
compare_benchmark_run_groups(
baselines: Sequence[BenchmarkRun],
candidates: Sequence[BenchmarkRun],
*,
compatibility_policy: RunCompatibilityPolicy
| None = None,
regression_policy: RegressionPolicy | None = None,
evidence_policy: EvidencePolicy | None = None,
inference_policy: InferencePolicy | None = None,
precision_policy: PrecisionPolicy | None = None,
) -> BenchmarkRunComparison
Compare repeated baseline and candidate runs as two evidence groups.
Each cell uses the median of its per-run metric values. By default, run-level BCa bootstrap intervals quantify uncertainty and a Bonferroni adjustment controls the matrix-wide family-wise error rate. Practical thresholds then distinguish improvements, regressions, equivalence, and inconclusive intervals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baselines
|
Sequence[BenchmarkRun]
|
Repeated reference benchmark runs. |
required |
candidates
|
Sequence[BenchmarkRun]
|
Repeated candidate benchmark runs. |
required |
compatibility_policy
|
RunCompatibilityPolicy | None
|
Environment checks applied across every run. |
None
|
regression_policy
|
RegressionPolicy | None
|
Percentage thresholds for classifying changes. |
None
|
evidence_policy
|
EvidencePolicy | None
|
Minimum repeated-run and sample evidence. |
None
|
inference_policy
|
InferencePolicy | None
|
Statistical inference and multiplicity controls. |
None
|
precision_policy
|
PrecisionPolicy | None
|
Optional paired fixed-design planning target. It must remain disabled for independent groups. |
None
|
Returns:
| Type | Description |
|---|---|
BenchmarkRunComparison
|
A matrix comparison with per-side trust diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If either run group is empty. |
TypeError
|
If a group contains a value other than |
Source code in src/benchmatrix/bench_compare.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
compare_paired_benchmark_run_groups ¶
compare_paired_benchmark_run_groups(
baselines: Sequence[BenchmarkRun],
candidates: Sequence[BenchmarkRun],
*,
pair_strata: Sequence[str] | None = None,
precision_pair_count_multiple: int = 2,
compatibility_policy: RunCompatibilityPolicy
| None = None,
regression_policy: RegressionPolicy | None = None,
evidence_policy: EvidencePolicy | None = None,
inference_policy: InferencePolicy | None = None,
precision_policy: PrecisionPolicy | None = None,
) -> BenchmarkRunComparison
Compare explicitly matched baseline/candidate process-run pairs.
The values at each position must come from one adjacent collection block. Complete pairs, rather than individual run files, are the independent experimental units. Pairing is explicit in this API and is never inferred from filenames or timestamps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
baselines
|
Sequence[BenchmarkRun]
|
Baseline members in pair order. |
required |
candidates
|
Sequence[BenchmarkRun]
|
Candidate members in the same pair order. |
required |
pair_strata
|
Sequence[str] | None
|
Optional fixed-design stratum label for each pair, such
as its recorded |
None
|
precision_pair_count_multiple
|
int
|
Divisibility constraint for a future confirmatory collection. Paired designs default to an even count; manifest-backed collections pass their complete joint design supercycle. |
2
|
compatibility_policy
|
RunCompatibilityPolicy | None
|
Environment checks applied across every run. |
None
|
regression_policy
|
RegressionPolicy | None
|
Percentage thresholds for classifying changes. |
None
|
evidence_policy
|
EvidencePolicy | None
|
Minimum complete-pair and sample evidence. |
None
|
inference_policy
|
InferencePolicy | None
|
Statistical inference and multiplicity controls. |
None
|
precision_policy
|
PrecisionPolicy | None
|
Optional fixed-design precision target for a fresh future paired collection. |
None
|
Returns:
| Type | Description |
|---|---|
BenchmarkRunComparison
|
A paired matrix comparison with per-side trust diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the sequences are empty or have different lengths. |
TypeError
|
If either sequence contains a non- |
Source code in src/benchmatrix/bench_compare.py
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 | |