From 748247f1eda545016550c1fdb3eb00cec72e278b Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Mon, 3 Jun 2024 12:33:36 +0200 Subject: [PATCH] Add jwutils.StopWatch Add StopWatch class, intended to be useful for benchmarking. Signed-off-by: Jan Lindemann --- tools/python/jwutils/StopWatch.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tools/python/jwutils/StopWatch.py diff --git a/tools/python/jwutils/StopWatch.py b/tools/python/jwutils/StopWatch.py new file mode 100644 index 0000000..1e2f712 --- /dev/null +++ b/tools/python/jwutils/StopWatch.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +import datetime +from .log import * + +class StopWatch: # export + + def __init__(self, name=''): + self.__start = datetime.now() + self.__last = self.__start + self.name = name + + def reset(self): + self.__start = datetime.now() + + def logDelta(self, prio, *args, **kwargs): + now = datetime.now() + if args is not None: + msg = ' '.join(args) + else: + msg = '------------------ ' + caller = kwargs['caller'] if 'caller' in kwargs.keys() else get_caller_pos(1) + slog(prio, '{} {} {}'.format(self.name, str(now - self.__last), msg), caller=caller) + self.__last = now