X-Portrait / utils /time_utils.py
fffiloni's picture
Migrated from GitHub
bfed184 verified
raw
history blame contribute delete
553 Bytes
# -*- coding: utf-8 -*-
import time
class Timer:
def __init__(self):
self.clock = {}
def start(self, key="default"):
self.clock[key] = time.time()
def end(self, key="default"):
if key not in self.clock:
raise Exception("{} is not in the clock.".format(key))
interval = time.time() - self.clock[key]
del self.clock[key]
return interval
def time_since(last_time):
time_elapsed = time.time() - last_time
current_time = time.time()
return current_time, time_elapsed