mlair.helpers.time_tracking
¶
Track time either as decorator or explicit.
Module Contents¶
Classes¶
Wrapper implementation of TimeTracking class. |
|
Track time to measure execution time. |
-
class
mlair.helpers.time_tracking.
TimeTrackingWrapper
(func)¶ Wrapper implementation of TimeTracking class.
Use this implementation easily as decorator for functions, classes and class methods. Implement a custom function and decorate it for automatic time measure.
@TimeTrackingWrapper def sleeper(): print("start") time.sleep(1) print("end") >>> sleeper() start end INFO: foo finished after 00:00:01 (hh:mm:ss)
-
__call__
(self, *args, **kwargs)¶ Start time tracking.
-
__get__
(self, instance, cls)¶ Create bound method object and supply self argument to the decorated method.
-
-
class
mlair.helpers.time_tracking.
TimeTracking
(start=True, name='undefined job', logging_level=logging.INFO, log_on_enter=False)¶ Bases:
object
Track time to measure execution time.
Time tracking automatically starts on initialisation and ends by calling stop method. Duration can always be shown by printing the time tracking object or calling get_current_duration. It is possible to start and stop time tracking by hand like
time = TimeTracking(start=True) # start=True is default and not required to set do_something() time.stop(get_duration=True)
A more comfortable way is to use TimeTracking in a with statement like:
with TimeTracking(): do_something()
The only disadvantage of the latter implementation is, that the duration is logged but not returned.
-
stop
(self, get_duration=False) → Optional[float]¶ Stop time tracking.
Will raise an error if time tracking was already stopped. :param get_duration: return passed time if enabled.
- Returns
duration if enabled or None
-
__enter__
(self)¶ Context manager.
-