-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreduce_baselines.py
More file actions
56 lines (46 loc) · 1.75 KB
/
Copy pathreduce_baselines.py
File metadata and controls
56 lines (46 loc) · 1.75 KB
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
"""Reduce pytest-benchmark JSON into benchmarks/baselines.json."""
from __future__ import annotations
import argparse
import json
import sys
from datetime import UTC, datetime
from pathlib import Path
GATED_GROUPS = ("parse", "export", "search")
def reduce_baselines(
raw_path: str | Path,
out_path: str | Path,
*,
slack: float = 1.0,
) -> dict[str, object]:
raw = json.loads(Path(raw_path).read_text(encoding="utf-8"))
groups: dict[str, dict[str, float]] = {group: {} for group in GATED_GROUPS}
for entry in raw["benchmarks"]:
group = entry.get("group")
if group not in GATED_GROUPS:
continue
groups[group][entry["name"]] = float(entry["stats"]["mean"]) * slack
machine_info = raw.get("machine_info", {})
output: dict[str, object] = {
"_note": "CI gates the ubuntu benchmarks job when mean exceeds baseline by >20%.",
"updated": datetime.now(UTC).strftime("%Y-%m-%dT%H:%M:%SZ"),
"machine": machine_info.get("system"),
"groups": groups,
}
path = Path(out_path)
path.write_text(json.dumps(output, indent=2) + "\n", encoding="utf-8")
return output
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("raw_path", help="pytest-benchmark --benchmark-json output")
parser.add_argument("out_path", help="destination baselines.json path")
parser.add_argument(
"--slack",
type=float,
default=1.0,
help="multiply means by this factor (e.g. 1.25 when capturing on a faster host)",
)
args = parser.parse_args(argv)
reduce_baselines(args.raw_path, args.out_path, slack=args.slack)
return 0
if __name__ == "__main__":
sys.exit(main())