Skip to content

Commit 0374b9a

Browse files
authored
Improve compare.py output to use min times and better column titles (#6134)
* Minor: improve output of compare.py * cleanup
1 parent a015798 commit 0374b9a

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

benchmarks/compare.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from __future__ import annotations
2121

2222
import json
23-
import statistics
2423
from dataclasses import dataclass
2524
from typing import Dict, List, Any
2625
from pathlib import Path
@@ -33,8 +32,6 @@
3332
print("Try `pip install rich` for using this script.")
3433
raise
3534

36-
MEAN_THRESHOLD = 5
37-
3835

3936
@dataclass
4037
class QueryResult:
@@ -64,14 +61,9 @@ def load_from(cls, data: Dict[str, Any]) -> QueryRun:
6461
def execution_time(self) -> float:
6562
assert len(self.iterations) >= 1
6663

67-
# If we don't have enough samples, median() is probably
68-
# going to be a worse measure than just an average.
69-
if len(self.iterations) < MEAN_THRESHOLD:
70-
method = statistics.mean
71-
else:
72-
method = statistics.median
73-
74-
return method(iteration.elapsed for iteration in self.iterations)
64+
# Use minimum execution time to account for variations / other
65+
# things the system was doing
66+
return min(iteration.elapsed for iteration in self.iterations)
7567

7668

7769
@dataclass
@@ -81,7 +73,6 @@ class Context:
8173
num_cpus: int
8274
start_time: int
8375
arguments: List[str]
84-
branch: str
8576

8677
@classmethod
8778
def load_from(cls, data: Dict[str, Any]) -> Context:
@@ -91,7 +82,6 @@ def load_from(cls, data: Dict[str, Any]) -> Context:
9182
num_cpus=data["num_cpus"],
9283
start_time=data["start_time"],
9384
arguments=data["arguments"],
94-
branch=data["arguments"][9]
9585
)
9686

9787

@@ -119,17 +109,19 @@ def compare(
119109
noise_threshold: float,
120110
) -> None:
121111
baseline = BenchmarkRun.load_from_file(baseline_path)
122-
baselineBranch = baseline.context.branch
123112

124113
comparison = BenchmarkRun.load_from_file(comparison_path)
125-
comparisonBranch = comparison.context.branch
126114

127115
console = Console()
128116

117+
# use basename as the column names
118+
baseline_header = baseline_path.stem
119+
comparison_header = comparison_path.stem
120+
129121
table = Table(show_header=True, header_style="bold magenta")
130122
table.add_column("Query", style="dim", width=12)
131-
table.add_column(baselineBranch, justify="right", style="dim", width=12)
132-
table.add_column(comparisonBranch, justify="right", style="dim", width=12)
123+
table.add_column(baseline_header, justify="right", style="dim")
124+
table.add_column(comparison_header, justify="right", style="dim")
133125
table.add_column("Change", justify="right", style="dim")
134126

135127
for baseline_result, comparison_result in zip(baseline.queries, comparison.queries):

0 commit comments

Comments
 (0)