Spaces:
Running
on
L40S
Running
on
L40S
File size: 553 Bytes
bfed184 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# -*- 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
|