Skip to content

Commit

Permalink
Feat/better stop watch (#10)
Browse files Browse the repository at this point in the history
* feat/better_stop_watch
adds new property delta to stopwatch class
authored-by: jarbasai <jarbasai@mailfence.com>
  • Loading branch information
JarbasAl authored Nov 17, 2021
1 parent 8f13603 commit 6908517
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions ovos_utils/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def start(self):
"""
Start a time measurement
"""
self.time = None
self.timestamp = time.time()

def lap(self):
Expand All @@ -21,13 +22,21 @@ def lap(self):
self.timestamp = cur_time
return cur_time - start_time

@property
def delta(self):
if not self.timestamp:
# stopped or not started
return self.time or 0
return time.time() - self.timestamp

def stop(self):
"""
Stop a running time measurement. returns the measured time
"""
cur_time = time.time()
start_time = self.timestamp
self.time = cur_time - start_time
self.timestamp = None
return self.time

def __enter__(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='ovos_utils',
version='0.0.14a2',
version='0.0.14a3',
packages=['ovos_utils',
'ovos_utils.intents',
'ovos_utils.sound',
Expand Down

0 comments on commit 6908517

Please sign in to comment.