forked from ChelseaKR/obligation-receipts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_m0.py
More file actions
62 lines (51 loc) · 2.13 KB
/
Copy pathbenchmark_m0.py
File metadata and controls
62 lines (51 loc) · 2.13 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
57
58
59
60
61
62
"""Report local M0 validation-and-evaluation latency without asserting a target."""
from __future__ import annotations
import argparse
import platform
from pathlib import Path
from statistics import median
from time import perf_counter_ns
from obligation_receipts.canonical import canonical_json_bytes
from obligation_receipts.evaluator import evaluate_manifest
from obligation_receipts.manifest import load_manifest
from obligation_receipts.models import JsonValue
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser()
parser.add_argument("--iterations", type=int, default=200)
parser.add_argument(
"--manifest",
type=Path,
default=Path("examples/accessibility-acceptance/obligations.toml"),
)
return parser
def _percentile(values: list[float], fraction: float) -> float:
ordered = sorted(values)
index = max(0, min(len(ordered) - 1, int(len(ordered) * fraction + 0.999999) - 1))
return ordered[index]
def main() -> int:
args = _parser().parse_args()
if not 1 <= args.iterations <= 10_000:
raise SystemExit("--iterations must be between 1 and 10000")
manifest_path: Path = args.manifest.resolve(strict=True)
evidence_root = manifest_path.parent / "evidence"
durations: list[float] = []
payload_sha256 = ""
for _ in range(args.iterations):
started = perf_counter_ns()
evaluation = evaluate_manifest(load_manifest(manifest_path), evidence_root)
durations.append((perf_counter_ns() - started) / 1_000_000)
payload_sha256 = evaluation.manifest_sha256
report: dict[str, JsonValue] = {
"iterations": args.iterations,
"manifest_sha256": payload_sha256,
"median_ms": round(median(durations), 3),
"p95_ms": round(_percentile(durations, 0.95), 3),
"platform": platform.platform(),
"python": platform.python_version(),
"scope": "manifest_validation_plus_four_obligation_evaluation",
"threshold_status": "not_set_pending_real_workload",
}
print(canonical_json_bytes(report).decode("utf-8"))
return 0
if __name__ == "__main__":
raise SystemExit(main())