mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
Add jwutils.StopWatch
Add StopWatch class, intended to be useful for benchmarking. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
27813efc04
commit
748247f1ed
1 changed files with 24 additions and 0 deletions
24
tools/python/jwutils/StopWatch.py
Normal file
24
tools/python/jwutils/StopWatch.py
Normal file
|
|
@ -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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue