tfunction profiler - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit d82529a41afb052f2f3bebdb24880372127f98b7 DIR parent cabd6bbb2c8c57eec6c5fe0219c1582ea9562f5a HTML Author: ThomasV <thomasv@gitorious> Date: Tue, 17 Mar 2015 11:29:17 +0100 function profiler Diffstat: M lib/util.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+), 0 deletions(-) --- DIR diff --git a/lib/util.py b/lib/util.py t@@ -77,6 +77,20 @@ def print_json(obj): sys.stdout.write(s + "\n") 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(): if "HOME" in os.environ: return os.path.join(os.environ["HOME"], ".electrum")