Skip to content

Instantly share code, notes, and snippets.

@c7h
Last active December 12, 2015 05:28
Show Gist options
  • Save c7h/4722329 to your computer and use it in GitHub Desktop.
Save c7h/4722329 to your computer and use it in GitHub Desktop.
primitive built-in debugging w. execution time measurement.
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