m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
417 B

6 months ago
  1. """
  2. Timer context manager, only used in debug.
  3. """
  4. from time import time
  5. import contextlib
  6. from typing import Generator
  7. @contextlib.contextmanager
  8. def timer(subject: str = "time") -> Generator[None, None, None]:
  9. """print the elapsed time. (only used in debugging)"""
  10. start = time()
  11. yield
  12. elapsed = time() - start
  13. elapsed_ms = elapsed * 1000
  14. print(f"{subject} elapsed {elapsed_ms:.1f}ms")