print "%s [%g seconds]" % (label, duration)
return wrapper
return debug_inner
+
+
+class DetailedTimer(object):
+ """ A detailed timer for overly complex functions.
+ """
+ def __init__(self, title, debug=False):
+ if DEBUG or debug:
+ self.title = title
+ self.times = []
+ else:
+ # fast funtions with the correct signature
+ self.start = int
+ self.show = str
+ self.lap = str
+ self.end = int
+
+ def start(self):
+ print "---- %s ----" % self.title
+ self.times.append(time.time())
+
+ def lap(self, label):
+ now = time.time()
+ print " %s: %s" % (label, now - self.times[-1])
+ self.times.append(now)
+
+ def show(self, text):
+ print " %s" % text
+
+ def end(self):
+ print " %s: %s" % ("total", time.time() - self.times[0])
+ print "---- ----"