Files
cutdex/tool/diagnostics/compare_property_performance.py
T
lingjhf 789af7a68e feat(inspector): edit animated effects, strokes and corner distortion
Replace the shadow-only inspector with layered effect and stroke controls and per-corner distortion editors. Share color inputs, layer rows, keyframe controls and property edit boundaries; keep nested selection menus within their property popover and update localized labels.

Add property editing, preview interaction and benchmark comparison coverage. Validation: Dart analysis reports no issues and 160 targeted application tests pass. The macOS development app was rebuilt and visually checked during native rendering validation. Exclude local dependency override changes from the committed lockfile.
2026-10-10 16:55:27 +08:00

89 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""Compare repeated release-mode PropertyPerformanceTests logs; fail on regressions."""
import argparse
import json
import math
import re
import statistics
from pathlib import Path
LINE = re.compile(
r"PROPERTY_BENCH (\w+) median_us=(\S+) p95_us=(\S+) checksum=(\S+)"
)
def read(paths):
runs = {}
for path in paths:
current = {}
for name, median, p95, checksum in LINE.findall(Path(path).read_text()):
values = tuple(float(value) for value in (median, p95, checksum))
if (name in current or not all(math.isfinite(value) for value in values)
or values[0] < 0 or values[1] < values[0]):
raise ValueError(f"Invalid or duplicate measurement in {path}: {name}")
current[name] = values
if not current or (runs and current.keys() != runs.keys()):
raise ValueError(f"Missing benchmark scenarios in {path}")
for name, values in current.items():
runs.setdefault(name, []).append(values)
return runs
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--before", nargs="+", required=True)
parser.add_argument("--after", nargs="+", required=True)
parser.add_argument("--output", type=Path)
parser.add_argument("--tolerance", type=float, default=0.15,
help="Allowed relative timing noise (default: 0.15)")
args = parser.parse_args()
if not 0 <= args.tolerance < 1:
parser.error("--tolerance must be in [0, 1)")
if len(args.before) < 3 or len(args.after) < 3:
parser.error("At least three independent runs are required on each side")
try:
before, after = read(args.before), read(args.after)
expected = {"render_plain", "render_effects", "sampling_empty", "sampling_normal", "sampling_dense"}
if before.keys() != expected or after.keys() != expected:
raise ValueError("Before/after scenarios do not match")
result = {
"method": "Median of independent run medians and run P95 values; times in microseconds",
"scope": "Scalar sampling and 640x360 native frozen-frame compositor, not display FPS",
"checksumScope": "Scalar outputs and rendered-frame work counters; pixel parity is tested separately",
"relativeNoiseTolerance": args.tolerance,
"beforeLogs": args.before,
"afterLogs": args.after,
"scenarios": {},
}
passed = True
for name in before:
checksums = {row[2] for row in before[name] + after[name]}
scenario = {"checksumMatches": len(checksums) == 1,
"beforeRuns": len(before[name]), "afterRuns": len(after[name])}
passed &= scenario["checksumMatches"]
# Timer noise dominates empty, sub-microsecond sampling measurements.
absolute_noise = 0.1 if name.startswith("sampling_") else 100.0
for index, metric in enumerate(["median", "p95"]):
old = statistics.median(row[index] for row in before[name])
new = statistics.median(row[index] for row in after[name])
limit = old * (1 + args.tolerance) + absolute_noise
scenario[metric] = {"beforeUs": old, "afterUs": new,
"changePercent": (new / old - 1) * 100 if old else None,
"limitUs": limit, "passed": new <= limit}
passed &= new <= limit
result["scenarios"][name] = scenario
result["passed"] = bool(passed)
encoded = json.dumps(result, indent=2) + "\n"
if args.output:
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(encoded)
print(encoded, end="")
return 0 if passed else 1
except (OSError, ValueError) as error:
parser.exit(2, f"Invalid benchmark input: {error}\n")
if __name__ == "__main__":
raise SystemExit(main())