Last active
December 12, 2015 05:28
-
-
Save c7h/4722329 to your computer and use it in GitHub Desktop.
primitive built-in debugging w. execution time measurement.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import inspect | |
start_time = time.time() | |
debuglevel = 2 #e.g: 0=no 1=error 2=info ... | |
def printdebug(level, message): | |
if debuglevel >= level: | |
curr_time = time.time() - start_time | |
caller = inspect.stack()[1][3] | |
print "[%.03fsec] %s: %s" % (curr_time, caller, message) | |
def somefoo(): | |
#do some foo... | |
printdebug(2, "foo done") | |
#do more foo... | |
somefoo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment