Skip to content

Commit ae633e6

Browse files
committed
feat: improve table style when displaying results
1 parent 5e0cbde commit ae633e6

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

src/pytest_codspeed/instruments/walltime.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from rich.console import Console
1010
from rich.table import Table
11+
from rich.text import Text
1112

1213
from pytest_codspeed.instruments import Instrument
1314

@@ -200,25 +201,29 @@ def _print_benchmark_table(self) -> None:
200201
table = Table(title="Benchmark Results")
201202

202203
table.add_column("Benchmark", justify="right", style="cyan", no_wrap=True)
203-
table.add_column("Time (best)", justify="right", style="green")
204+
table.add_column("Time (best)", justify="right", style="green bold")
204205
table.add_column(
205206
"Rel. StdDev",
206207
justify="right",
207208
)
208-
table.add_column("Iter x Rounds", justify="right", style="blue")
209-
table.add_column("Outlier ratio", justify="right", style="blue")
209+
table.add_column("Run time", justify="right")
210+
table.add_column("Iters", justify="right")
210211

211212
for bench in self.benchmarks:
212213
rsd = bench.stats.stdev_ns / bench.stats.mean_ns
214+
rsd_text = Text(f"{rsd*100:.1f}%")
215+
if rsd > 0.1:
216+
rsd_text.stylize("red bold")
213217
table.add_row(
214218
bench.name,
215-
f"{bench.stats.min_ns/bench.stats.iter_per_round:.2f}ns",
216-
f"{rsd*100:.1f}%",
217-
f"{bench.stats.iter_per_round} x {bench.stats.rounds}",
218-
f"{(bench.stats.outlier_rounds / bench.stats.rounds)*100:.1f}%",
219+
f"{bench.stats.min_ns/bench.stats.iter_per_round:,.0f}ns",
220+
rsd_text,
221+
f"{bench.stats.total_time:,.2f}s",
222+
f"{bench.stats.iter_per_round * bench.stats.rounds:,}",
219223
)
220224

221225
console = Console()
226+
print("\n")
222227
console.print(table)
223228

224229
def get_result_dict(self) -> dict[str, Any]:

src/pytest_codspeed/plugin.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class CodSpeedPlugin:
9696
instrument: Instrument
9797
config: CodSpeedConfig
9898
disabled_plugins: tuple[str, ...]
99-
result_path: Path | None
99+
profile_folder: Path | None
100100
benchmark_count: int = field(default=0, hash=False, compare=False)
101101

102102

@@ -143,10 +143,6 @@ def pytest_configure(config: pytest.Config):
143143
disabled_plugins.append("pytest-speed")
144144

145145
profile_folder = os.environ.get("CODSPEED_PROFILE_FOLDER")
146-
if profile_folder:
147-
result_path = Path(profile_folder) / "results" / f"{os.getpid()}.json"
148-
else:
149-
result_path = config.rootpath / f".codspeed/results_{time() * 1000:.0f}.json"
150146

151147
codspeedconfig = CodSpeedConfig.from_pytest_config(config)
152148

@@ -156,7 +152,7 @@ def pytest_configure(config: pytest.Config):
156152
mode=mode,
157153
instrument=instrument(codspeedconfig),
158154
config=codspeedconfig,
159-
result_path=result_path,
155+
profile_folder=Path(profile_folder) if profile_folder else None,
160156
)
161157
config.pluginmanager.register(plugin, PLUGIN_NAME)
162158

@@ -297,10 +293,15 @@ def pytest_sessionfinish(session: pytest.Session, exitstatus):
297293
plugin = get_plugin(session.config)
298294
if plugin.is_codspeed_enabled:
299295
plugin.instrument.report(session)
300-
if plugin.result_path is not None:
301-
data = {**get_environment_metadata(), **plugin.instrument.get_result_dict()}
302-
plugin.result_path.parent.mkdir(parents=True, exist_ok=True)
303-
plugin.result_path.write_text(json.dumps(data, indent=2))
296+
if plugin.profile_folder:
297+
result_path = plugin.profile_folder / "results" / f"{os.getpid()}.json"
298+
else:
299+
result_path = (
300+
session.config.rootpath / f".codspeed/results_{time() * 1000:.0f}.json"
301+
)
302+
data = {**get_environment_metadata(), **plugin.instrument.get_result_dict()}
303+
result_path.parent.mkdir(parents=True, exist_ok=True)
304+
result_path.write_text(json.dumps(data, indent=2))
304305

305306

306307
class BenchmarkFixture:

0 commit comments

Comments
 (0)