From fbe1062016a06f39b908f4f050f82ce8fa78008e Mon Sep 17 00:00:00 2001 From: Simon Cross Date: Fri, 9 Sep 2016 20:36:45 +0200 Subject: [PATCH] Add utility for detailed performance profiling. --- tabakrolletjie/utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tabakrolletjie/utils.py b/tabakrolletjie/utils.py index b605ba1..0775204 100644 --- a/tabakrolletjie/utils.py +++ b/tabakrolletjie/utils.py @@ -21,3 +21,34 @@ def debug_timer(label, debug=False): 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 "---- ----" -- 2.34.1