Skip to content

Commit bbf3e7f

Browse files
kddnewtonmeta-codesync[bot]
authored andcommitted
Add JIT compilation speed benchmark
Summary: Add a benchmark that measures JIT compilation time (not runtime performance of generated code). It collects functions from the existing benchmark modules, force-compiles each one, and reports per-function and aggregate timing in microseconds. Run with: buck run //cinderx/benchmarks:compile-time Reviewed By: alexmalyshev Differential Revision: D98906989 fbshipit-source-id: 7182476a84026f1acdf534ef870a1ddf2b22c8c8
1 parent 16c708f commit bbf3e7f

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

cinderx/benchmarks/compile_time.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
3+
# pyre-strict
4+
5+
"""
6+
JIT compilation speed benchmark.
7+
8+
Measures how long it takes the CinderX JIT to compile functions, not the
9+
runtime performance of the generated code. Uses compile_after_n_calls(0) to
10+
eagerly compile all functions on import, then reports per-function and
11+
aggregate timing statistics.
12+
13+
Usage:
14+
buck run //cinderx/benchmarks:compile-time
15+
16+
For a per-phase breakdown of each function's compilation, pass the jit-time
17+
flag via Python's -X option:
18+
buck run //cinderx/benchmarks:compile-time -- -X jit-time='*'
19+
"""
20+
21+
from __future__ import annotations
22+
23+
import logging
24+
25+
import cinderx.jit
26+
27+
logger: logging.Logger = logging.getLogger(__name__)
28+
29+
30+
def main() -> None:
31+
cinderx.jit.compile_after_n_calls(0)
32+
33+
# Importing these modules triggers JIT compilation of all their functions.
34+
# These are bundled via srcs in the BUCK target, not as separate deps.
35+
from cinderx.benchmarks import ( # noqa: F811 # @manual
36+
binary_trees,
37+
fannkuch,
38+
nbody,
39+
richards,
40+
spectral_norm,
41+
)
42+
43+
# Suppress unused import warnings.
44+
_ = (binary_trees, fannkuch, nbody, richards, spectral_norm)
45+
46+
cinderx.jit.disable()
47+
48+
results: list[tuple[str, float]] = []
49+
for func in cinderx.jit.get_compiled_functions():
50+
comp_time = cinderx.jit.get_function_compilation_time(func)
51+
name = f"{func.__module__}:{func.__qualname__}"
52+
results.append((name, comp_time))
53+
54+
results.sort(key=lambda r: r[1], reverse=True)
55+
56+
print(f"{'Function':<60} {'Time (ms)':>10}")
57+
print("-" * 71)
58+
for name, t in results:
59+
print(f"{name:<60} {t:>10.3f}")
60+
61+
total = sum(t for _, t in results)
62+
print("-" * 71)
63+
print(f"{'Total':<60} {total:>10.3f}")
64+
print(f"{'Functions compiled':<60} {len(results):>10}")
65+
66+
67+
if __name__ == "__main__":
68+
main()

0 commit comments

Comments
 (0)