timeit.py 808 B

1234567891011121314151617181920212223242526272829
  1. import importlib
  2. def import_optional_module(module_name):
  3. # Initialize the cache attribute if it does not exist
  4. if not hasattr(import_optional_module, 'cache'):
  5. import_optional_module.cache = {}
  6. # Check if the module is already in the cache
  7. if module_name in import_optional_module.cache:
  8. return import_optional_module.cache[module_name]
  9. # Attempt to import the module
  10. try:
  11. module = importlib.import_module(module_name)
  12. except ImportError:
  13. module = None
  14. # Cache the result
  15. import_optional_module.cache[module_name] = module
  16. return module
  17. def timeit(func):
  18. logging = import_optional_module("devtools.frontend_build_platform.libraries.logging")
  19. if logging:
  20. return logging.timeit(func)
  21. else:
  22. return func