X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=tabakrolletjie%2Futils.py;h=0775204345e60a94146164feb2966bdecb886642;hb=693cbe7873f08eaa96ec6a0edd8bba08870307bf;hp=b605ba15f8b6287a82be2e3943c9194fb30c8b9f;hpb=2dc2a3172f0b9a28bb5b688926be1a9e10213512;p=tabakrolletjie.git 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 "---- ----"