function profiler

This commit is contained in:
ThomasV 2015-03-17 11:29:17 +01:00
parent cabd6bbb2c
commit d82529a41a
1 changed files with 14 additions and 0 deletions

View File

@ -77,6 +77,20 @@ def print_json(obj):
sys.stdout.write(s + "\n") sys.stdout.write(s + "\n")
sys.stdout.flush() sys.stdout.flush()
# decorator that prints execution time
def profiler(func):
def do_profile(func, args):
n = func.func_name
t0 = time.time()
o = apply(func, args)
t = time.time() - t0
print_error("[profiler]", n, "%.4f"%t)
return o
return lambda *args: do_profile(func, args)
def user_dir(): def user_dir():
if "HOME" in os.environ: if "HOME" in os.environ:
return os.path.join(os.environ["HOME"], ".electrum") return os.path.join(os.environ["HOME"], ".electrum")