fastdev.utils.profile ===================== .. py:module:: fastdev.utils.profile Module Contents --------------- .. py:class:: timeit(fn_or_print_tmpl: Optional[Union[Callable, str]] = None) Measure the time of a block of code. :param print_tmpl: The template to print the time. Defaults to None. Can be a string with a placeholder for the time, e.g., "func foo costs {:.5f} s" or a string without a placeholder, e.g., "func foo". :type print_tmpl: str, optional .. rubric:: Examples >>> with timeit(): ... time.sleep(1) it costs 1.00000 s >>> @timeit ... def foo(): ... time.sleep(1) foo costs 1.00000 s >>> @timeit("func foo") ... def foo(): ... time.sleep(1) func foo costs 1.00000 s .. py:method:: __enter__() .. py:method:: __exit__(exec_type, exec_value, traceback) .. py:method:: __call__(func: T) -> T .. py:class:: cuda_timeit(print_tmpl: Optional[str] = None) Bases: :py:obj:`timeit` Measure the time of a block of code that may involve CUDA operations. We use CUDA events and synchronization for the accurate measurements. :param print_tmpl: The template to print the time. Defaults to None. Can be a string with a placeholder for the time, e.g., "func foo costs {:.5f} s" or a string without a placeholder, e.g., "func foo". :type print_tmpl: str, optional .. py:method:: __enter__() .. py:method:: __exit__(exec_type, exec_value, traceback)