oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env python3
2"""Join run-clients.sh's typing and watching sides by key index: per key,
3the time from keydown on one copy to the "Q" showing on the other (the
4browser: DOM updated; native: rendered and reconciled into the text
5storage). Prints median / p95 per combination and writes latency.json."""
6import json, math, sys
7from pathlib import Path
8
9out = Path(sys.argv[1])
10
11def pct(xs, p):
12 s = sorted(xs)
13 return s[max(0, math.ceil(p * len(s)) - 1)] if s else float("nan")
14
15def load(name):
16 path = out / name
17 return json.loads(path.read_text()) if path.exists() else {}
18
19pairs = {
20 "web -> web": (load("web-web.json").get("keys"), load("web-web.json").get("seen")),
21 "native -> native": (load("nn-types.json").get("keys"), load("nn-watch.json").get("seen")),
22 "native -> web": (load("nw-types.json").get("keys"), load("nw-watch.json").get("seen")),
23 "web -> native": (load("wn-types.json").get("keys"), load("wn-watch.json").get("seen")),
24}
25result = {}
26for name, (keys, seen) in pairs.items():
27 if not keys or not seen:
28 print(f"{name:18} missing")
29 continue
30 lat = [s[1] - keys[int(s[0])] for s in seen if 0 <= int(s[0]) < len(keys)]
31 result[name] = {"n": len(lat), "keys": len(keys), "p50": pct(lat, 0.5), "p95": pct(lat, 0.95), "max": max(lat)}
32 print(f"{name:18} keys {len(keys):4} seen {len(lat):4} p50 {pct(lat, .5):7.1f} ms p95 {pct(lat, .95):7.1f} ms max {max(lat):7.1f} ms")
33(out / "latency.json").write_text(json.dumps(result, indent=1))
34