Skip to content

Instantly share code, notes, and snippets.

@zhasm
Created December 28, 2010 05:25
Show Gist options
  • Save zhasm/756925 to your computer and use it in GitHub Desktop.
Save zhasm/756925 to your computer and use it in GitHub Desktop.
a not very accurate timer in python
from time import time
class Timer():
def __init__(self):
self.begin=0
self.secs=0
def start(self):
self.begin=int(time())
def stop(self):
self.secs=int(time())-self.begin
def __repr__(self):
secs=self.secs
result=""
if secs>3600:
result+="%d hours " % int(secs/3600)
secs=secs % 3600
if secs>60:
result+="%d mins " % int (secs/60)
secs=secs % 60
if result:
result+=" and %d secs, or %d secs" % ( secs, secs)
else:
result="%d seconds" % secs
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment