-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualizer.py
57 lines (47 loc) · 1.63 KB
/
visualizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from rich import print
from rich.table import Table
from rich.panel import Panel
from rich.align import Align
from rich.console import Group
from rich.console import Console
from Utilities import get_visualizer_setup, centered_text
from rich.terminal_theme import SVG_EXPORT_THEME
console = Console(record=True)
def build_table() -> Table:
table = Table()
table.add_column("Version")
table.add_column("CPython")
table.add_column("Nuitka")
table.add_column(centered_text("Nuitka-Diff"))
table.add_column(centered_text("Factory Diff"))
return table
dates: dict[str, list[Table]] = {}
# for name, date, benchmarks in get_visualizer_setup():
for name, date, benchmarks in get_visualizer_setup():
table = build_table()
for benchmark in benchmarks:
nuitka_stats = benchmark.calculate_stats("nuitka")
cpython_stats = benchmark.calculate_stats("cpython")
factory_stats = (
benchmark.factory.format_stats()
if benchmark.factory
else centered_text("N/A")
)
table.title = name
table.add_row(
centered_text(benchmark.py_version),
centered_text(f"{cpython_stats:.2f}"),
centered_text(f"{nuitka_stats:.2f}"),
benchmark.format_stats(),
factory_stats,
)
dates.setdefault(date, []).append(table)
if not dates:
raise SystemExit("No data to visualize")
grid = Table.grid(expand=True)
rows = []
for date, tables in dates.items():
rows.append(Panel(Group(*tables), title=date, expand=False))
grid.add_row(*rows[-3:])
console.print(Align.center(grid))
console.save_svg("test.svg")