Skip to content
Snippets Groups Projects
Select Git revision
  • f76be7cff71bfe6d8142b79ff8b7241b5fb31128
  • main default protected
  • hookup-to-django
  • small-test-to-test-pipeline
  • connect-to-adex_cache_fastapi-database
  • improve_alta_algorithm
6 results

utils.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    utils.py 667 B
    """
    common helper functions
    """
    import logging;
    from datetime import *
    import time
    
    logger = logging.getLogger(__name__)
    
    # this is a decorator that can be put in front (around) a function all to measure its execution time
    def timeit(method):
        def timed(*args, **kw):
            ts = time.time()
            result = method(*args, **kw)
            te = time.time()
            if 'log_time' in kw:
                name = kw.get('log_name', method.__name__.upper())
                kw['log_time'][name] = int((te - ts) * 1000)
            else:
                print('execution time: %r  %2.2f ms' % \
                      (method.__name__, (te - ts) * 1000))
            return result
        return timed