diff --git a/build_tools/build_ext.py b/build_tools/build_ext.py index 631b2b3627..d7351a8617 100644 --- a/build_tools/build_ext.py +++ b/build_tools/build_ext.py @@ -10,6 +10,7 @@ import sys import sysconfig import copy +import time from pathlib import Path from subprocess import CalledProcessError @@ -81,6 +82,7 @@ def _build_cmake(self, build_dir: Path, install_dir: Path) -> None: build_command.append(str(max_jobs)) # Run CMake commands + start_time = time.perf_counter() for command in [configure_command, build_command, install_command]: print(f"Running command {' '.join(command)}") try: @@ -88,6 +90,9 @@ def _build_cmake(self, build_dir: Path, install_dir: Path) -> None: except (CalledProcessError, OSError) as e: raise RuntimeError(f"Error when running CMake: {e}") + total_time = time.perf_counter() - start_time + print(f"Time for build_ext: {total_time:.2f} seconds") + def get_build_ext(extension_cls: Type[setuptools.Extension]): class _CMakeBuildExtension(extension_cls): diff --git a/setup.py b/setup.py index 6a8bae2793..d1dd35c027 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,12 @@ """Installation script.""" import os +import time from pathlib import Path from typing import List, Tuple import setuptools +from wheel.bdist_wheel import bdist_wheel from build_tools.build_ext import CMakeExtension, get_build_ext from build_tools.utils import ( @@ -39,10 +41,23 @@ install_and_import("pybind11[global]") from pybind11.setup_helpers import build_ext as BuildExtension +# Start timing +start_time = time.perf_counter() + CMakeBuildExtension = get_build_ext(BuildExtension) +class TimedBdist(bdist_wheel): + """Helper class to measure build time""" + + def run(self): + start_time = time.perf_counter() + super().run() + total_time = time.perf_counter() - start_time + print(f"Time for bdist_wheel: {total_time:.2f} seconds") + + def setup_common_extension() -> CMakeExtension: """Setup CMake extension for common library""" # Project directory root @@ -141,7 +156,7 @@ def setup_requirements() -> Tuple[List[str], List[str], List[str]]: }, description="Transformer acceleration library", ext_modules=ext_modules, - cmdclass={"build_ext": CMakeBuildExtension}, + cmdclass={"build_ext": CMakeBuildExtension, "bdist_wheel": TimedBdist}, python_requires=">=3.8, <3.13", classifiers=[ "Programming Language :: Python :: 3.8", @@ -156,3 +171,8 @@ def setup_requirements() -> Tuple[List[str], List[str], List[str]]: include_package_data=True, package_data={"": ["VERSION.txt"]}, ) + + # End timing + end_time = time.perf_counter() + total_time = end_time - start_time + print(f"Total build time: {total_time:.2f} seconds")