mirror of
https://github.com/burakgon/OpenScreens.git
synced 2026-12-06 07:40:26 +08:00
The figures were a table near the end of what the app does. They now come first after the picture at the top: a chart of the frames each app put on the glass and the processor it took, a few lines on what they mean, and the table under them. scripts/speed-chart.py draws the chart from the figures in docs/PERFORMANCE.md, once for a light page and once for a dark one. Each sits on a card in its own page's colour, so either still reads if a viewer shows it on the other page. The section keeps the anchor the old one had.
153 lines
8.1 KiB
Python
Executable File
153 lines
8.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
||
"""Draws the read-me's chart of how fast the app is, for a light page and a dark one.
|
||
|
||
python3 scripts/speed-chart.py [docs/images]
|
||
|
||
writes speed-light.svg and speed-dark.svg. The figures are the ones in
|
||
docs/PERFORMANCE.md, typed in below: when those are measured again, change
|
||
them here too and draw the chart again.
|
||
|
||
Each figure is the lowest and the highest of the runs. A bar is solid to the
|
||
lowest and pale to the highest, so a spread between runs is shown rather than
|
||
averaged away. OpenScreens 1.4.0 is the one in colour; Apple's Screen Sharing
|
||
and 1.3.0 are there to be measured against.
|
||
"""
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
# Standard, with a Mac: of the frames the Mac drew, the share that was shown.
|
||
FRAMES = [
|
||
("A still desktop", {"new": (96, 99), "apple": (84, 90), "old": (59, 61)}),
|
||
("Scrolling", {"new": (95, 97), "apple": (91, 94), "old": (84, 86)}),
|
||
("A moving picture", {"new": (98, 99), "apple": (87, 90), "old": (70, 72)}),
|
||
]
|
||
# The app's share of one processor core, over the three loads. Apple's app is
|
||
# left out: its window was larger than the app's when it was measured.
|
||
PROCESSOR = [
|
||
("Standard", {"new": (28, 49), "old": (73, 98)}),
|
||
("High Performance", {"new": (19, 22), "old": (48, 53)}),
|
||
]
|
||
NAMES = {"new": "OpenScreens 1.4.0", "apple": "Apple’s Screen Sharing", "old": "OpenScreens 1.3.0"}
|
||
|
||
# The blue and the grey were checked for telling apart with every kind of
|
||
# colour blindness; the value written beside each bar names it as well.
|
||
THEMES = {
|
||
"light": dict(surface="#ffffff", text="#1f2328", muted="#59636e", grid="#e6e8eb", base="#c8ccd1",
|
||
new="#257de0", apple="#6e7781", old="#84b9f3"),
|
||
"dark": dict(surface="#0d1117", text="#e6edf3", muted="#9198a1", grid="#232a33", base="#3d444d",
|
||
new="#338ced", apple="#8b949e", old="#1757ac"),
|
||
}
|
||
FONT = "-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif"
|
||
BAR = 15 # how thick a bar is
|
||
GAP = 3 # the air between the bars of a group
|
||
RADIUS = 4 # the rounding at a bar's end
|
||
|
||
|
||
def bar(x, y, length, colour, rounded=True, opacity=None):
|
||
"""A bar from the axis at x: square there, rounded at its end."""
|
||
if length <= 0:
|
||
return ""
|
||
fill = f' fill="{colour}"' + (f' fill-opacity="{opacity}"' if opacity is not None else "")
|
||
r = min(RADIUS, length / 2, BAR / 2) if rounded else 0
|
||
if r == 0:
|
||
return f'<rect x="{x:.1f}" y="{y:.1f}" width="{length:.1f}" height="{BAR}"{fill}/>'
|
||
return (f'<path d="M{x:.1f},{y:.1f} h{length - r:.1f} a{r},{r} 0 0 1 {r},{r} v{BAR - 2 * r:.1f} '
|
||
f'a{r},{r} 0 0 1 {-r},{r} h{-(length - r):.1f} z"{fill}/>')
|
||
|
||
|
||
def panel(out, t, x0, top, width, title, subtitle, groups, keys):
|
||
"""A titled group of bars on a scale of 0 to 100%; returns where it ends."""
|
||
scale = (width - 78) / 100 # room after the longest bar for its value
|
||
out.append(f'<text x="{x0}" y="{top}" font-size="17" font-weight="600" fill="{t["text"]}">{title}</text>')
|
||
out.append(f'<text x="{x0}" y="{top + 21}" font-size="13" fill="{t["muted"]}">{subtitle}</text>')
|
||
y = top + 50
|
||
plot_top = y - 6
|
||
bars = []
|
||
for name, values in groups:
|
||
bars.append(f'<text x="{x0}" y="{y + 4}" font-size="13" font-weight="500" fill="{t["text"]}">{name}</text>')
|
||
y += 12
|
||
for key in keys:
|
||
low, high = values[key]
|
||
colour = t[key]
|
||
if high > low:
|
||
bars.append(bar(x0, y, high * scale, colour, opacity=0.38))
|
||
bars.append(bar(x0, y, low * scale, colour, rounded=False))
|
||
else:
|
||
bars.append(bar(x0, y, high * scale, colour))
|
||
label = f"{low}–{high}%" if high > low else f"{low}%"
|
||
weight = ' font-weight="600"' if key == "new" else ""
|
||
ink = t["text"] if key == "new" else t["muted"]
|
||
bars.append(f'<text x="{x0 + high * scale + 7:.1f}" y="{y + BAR - 3.5:.1f}" font-size="12.5"{weight} '
|
||
f'fill="{ink}" style="font-variant-numeric: tabular-nums">{label}</text>')
|
||
y += BAR + GAP
|
||
y += 20
|
||
plot_bottom = y - 18
|
||
# The grid goes down first, so the bars sit on it.
|
||
for tick in (0, 25, 50, 75, 100):
|
||
gx = x0 + tick * scale
|
||
colour = t["base"] if tick == 0 else t["grid"]
|
||
out.append(f'<line x1="{gx:.1f}" y1="{plot_top}" x2="{gx:.1f}" y2="{plot_bottom}" '
|
||
f'stroke="{colour}" stroke-width="1"/>')
|
||
out.append(f'<text x="{gx:.1f}" y="{plot_bottom + 16}" font-size="11" fill="{t["muted"]}" text-anchor="middle" '
|
||
f'style="font-variant-numeric: tabular-nums">{tick}{"%" if tick == 100 else ""}</text>')
|
||
out.extend(bars)
|
||
return plot_bottom + 16
|
||
|
||
|
||
def figure(out, t, x, y, label, value, lines):
|
||
"""One number, large, with what it is above it and what it means below."""
|
||
out.append(f'<text x="{x}" y="{y}" font-size="13" fill="{t["muted"]}">{label}</text>')
|
||
out.append(f'<text x="{x}" y="{y + 34}" font-size="28" font-weight="600" fill="{t["text"]}">{value}</text>')
|
||
for i, line in enumerate(lines):
|
||
out.append(f'<text x="{x}" y="{y + 56 + i * 17}" font-size="12.5" fill="{t["muted"]}">{line}</text>')
|
||
|
||
|
||
def chart(theme):
|
||
t = THEMES[theme]
|
||
margin = 24
|
||
body = []
|
||
x = 0
|
||
for key in ("new", "apple", "old"):
|
||
body.append(f'<rect x="{x}" y="6" width="12" height="12" rx="3" fill="{t[key]}"/>')
|
||
body.append(f'<text x="{x + 19}" y="16.5" font-size="13" fill="{t["text"]}">{NAMES[key]}</text>')
|
||
x += 19 + {"new": 132, "apple": 166, "old": 132}[key] + 26
|
||
frames_end = panel(body, t, 0, 62, 540, "Frames on your screen", "Standard mode · higher is better",
|
||
FRAMES, ("new", "apple", "old"))
|
||
processor_end = panel(body, t, 600, 62, 360, "Processor", "The app’s share of one core · lower is better",
|
||
PROCESSOR, ("new", "old"))
|
||
# Under the processor, where the frames run on, two figures that are not bars.
|
||
figure(body, t, 600, processor_end + 44, "Delay, Mac to glass", "2 refreshes",
|
||
["As soon as that Mac shows", "anything in a window"])
|
||
figure(body, t, 800, processor_end + 44, "Torn pictures", "0–2%",
|
||
["of refreshes. Apple’s", "Screen Sharing: 6–16%"])
|
||
footer = max(frames_end, processor_end) + 30
|
||
body.append(f'<text x="0" y="{footer}" font-size="11.5" fill="{t["muted"]}">Measured on the display itself: '
|
||
f'Mac mini (M4), 3440 × 1440 at 50 Hz, connected to itself. '
|
||
f'Solid to the lowest run, pale to the highest.</text>')
|
||
width, height = 960 + 2 * margin, footer + 6 + 2 * margin
|
||
return "\n".join([
|
||
f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}" '
|
||
f'font-family="{FONT}" role="img" aria-labelledby="title desc">',
|
||
'<title id="title">How fast OpenScreens is</title>',
|
||
'<desc id="desc">In Standard mode OpenScreens 1.4.0 puts 96 to 99% of a Mac’s frames on the screen with a still '
|
||
'desktop, 95 to 97% while scrolling and 98 to 99% with a moving picture; Apple’s Screen Sharing 84 to 90, 91 to 94 '
|
||
'and 87 to 90%; OpenScreens 1.3.0 59 to 61, 84 to 86 and 70 to 72%. The app uses 28 to 49% of one processor core '
|
||
'in Standard where 1.3.0 used 73 to 98%, and 19 to 22% in High Performance where 1.3.0 used 48 to 53%. A frame '
|
||
'is on the screen two refreshes after the Mac drew it, and 0 to 2% of refreshes show two frames at once, against '
|
||
'6 to 16% for Apple’s Screen Sharing.</desc>',
|
||
# A card in the page's own colour: it cannot be seen on the page it was
|
||
# made for, and keeps the chart legible if a viewer shows it on the other.
|
||
f'<rect width="{width}" height="{height}" rx="12" fill="{t["surface"]}"/>',
|
||
f'<g transform="translate({margin} {margin})">',
|
||
*body,
|
||
'</g></svg>',
|
||
]) + "\n"
|
||
|
||
|
||
if __name__ == "__main__":
|
||
target = Path(sys.argv[1] if len(sys.argv) > 1 else "docs/images")
|
||
for theme in THEMES:
|
||
path = target / f"speed-{theme}.svg"
|
||
path.write_text(chart(theme))
|
||
print(path)
|