fastdev.utils.profile¶
Module Contents¶
- class fastdev.utils.profile.timeit(fn_or_print_tmpl: Callable | str | None = None)[source]¶
Measure the time of a block of code.
- Parameters:
print_tmpl (str, optional) – 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”.
fn_or_print_tmpl (Optional[Union[Callable, str]])
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
- class fastdev.utils.profile.cuda_timeit(print_tmpl: str | None = None)[source]¶
Bases:
timeit
Measure the time of a block of code that may involve CUDA operations. We use CUDA events and synchronization for the accurate measurements.
- Parameters:
print_tmpl (str, optional) – 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”.