ATLAS Offline Software
Loading...
Searching...
No Matches
timed.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3from AthenaCommon import Logging
4from ..utility import RepeatingTimer
5import datetime
6from functools import wraps
7
8
9logger = Logging.logging.getLogger("PowhegControl")
10
11
12def timed(name):
13 """! Decorator to output function execution time.
14
15 @param name Name of the process being timed.
16
17 @author James Robinson <james.robinson@cern.ch>
18 """
19 def wrap(func):
20 @wraps(func)
21 def wrapped_f(*args, **kwargs):
22 start_time = datetime.datetime.now()
23 logger.info("=> Preparing to run {} <=".format(name))
24 result = func(*args, **kwargs)
25 logger.info("=> Running {} took {} <=".format(name, RepeatingTimer.readable_duration(datetime.datetime.now() - start_time)))
26 return result
27 return wrapped_f
28 return wrap