lean4-htt/tests/bench-radar/size/run
Garmelon debafca7e1
chore: add radar-based bench suite for stdlib (#11264)
This PR adds a new [radar]-based [temci]-less bench suite that replaces
the `stdlib` benchmarks from the old suite and also measures per-module
instruction counts. All other benchmarks from the old suite are
unaffected.

The readme at `tests/bench-radar/README.md` explains in more detail how
the bench suite is structured and how it works. The readmes in the
benchmark subdirectories explain what each benchmark does and which
metrics it collects.

All metrics except `stdlib//max dynamic symbols` were ported to the new
suite, though most have been renamed.

[radar]: https://github.com/leanprover/radar
[temci]: https://github.com/parttimenerd/temci
2025-11-25 12:59:30 +00:00

64 lines
2 KiB
Python
Executable file

#!/usr/bin/env python3
import json
from pathlib import Path
from typing import Iterable
SRC = Path("src")
STAGE3 = Path("build/release/stage3")
STAGE3_TEMP = STAGE3 / "lib" / "temp"
STAGE3_LEAN = STAGE3 / "lib" / "lean"
def print_result(metric: str, value: float, unit: str | None = None) -> None:
data = {"metric": metric, "value": value}
if unit is not None:
data["unit"] = unit
print(f"radar::measurement={json.dumps(data)}")
def measure_bytes(topic: str, paths: Iterable[Path], files: bool = True) -> None:
amount = 0
total = 0
for path in paths:
amount += 1
total += path.stat().st_size
if files:
print_result(f"{topic}//files", amount)
print_result(f"{topic}//bytes", total, "B")
def measure_lines(topic: str, paths: Iterable[Path]) -> None:
amount = 0
total = 0
for path in paths:
amount += 1
with open(path) as f:
total += sum(1 for _ in f)
print_result(f"{topic}//files", amount)
print_result(f"{topic}//lines", total)
if __name__ == "__main__":
measure_bytes(
"size/libleanshared.so",
[STAGE3_LEAN / "libleanshared.so"],
files=False,
)
# Stdlib
measure_lines("size/stdlib/.c", STAGE3_TEMP.glob("**/*.c"))
measure_bytes("size/stdlib/.ir", STAGE3_LEAN.glob("**/*.ir"))
measure_lines("size/stdlib/.cpp", SRC.glob("**/*.cpp"))
measure_lines("size/stdlib/.lean", SRC.glob("**/*.lean"))
measure_bytes("size/stdlib/.ilean", STAGE3_LEAN.glob("**/*.ilean"))
measure_bytes("size/stdlib/.olean", STAGE3_LEAN.glob("**/*.olean"))
measure_bytes("size/stdlib/.olean.server", STAGE3_LEAN.glob("**/*.olean.server"))
measure_bytes("size/stdlib/.olean.private", STAGE3_LEAN.glob("**/*.olean.private"))
# Init
measure_bytes("size/init/.olean", STAGE3_LEAN.glob("Init/**/*.olean"))
measure_bytes("size/init/.olean.server", STAGE3_LEAN.glob("Init/**/*.olean.server"))
measure_bytes(
"size/init/.olean.private", STAGE3_LEAN.glob("Init/**/*.olean.private")
)