From ef62d86cf45c7ebaa817c1901a9cb0aefc6e6191 Mon Sep 17 00:00:00 2001 From: Cefn Hoile Date: Sun, 18 Feb 2018 01:41:38 +0000 Subject: [PATCH] Module for function-performance-profiling decorator --- python/testing/profiling/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 python/testing/profiling/__init__.py diff --git a/python/testing/profiling/__init__.py b/python/testing/profiling/__init__.py new file mode 100644 index 0000000..0d584f6 --- /dev/null +++ b/python/testing/profiling/__init__.py @@ -0,0 +1,11 @@ +def time_function(f): + from agnostic import time + """From http://docs.micropython.org/en/latest/esp8266/reference/speed_python.html""" + myname = str(f).split(' ')[1] + def new_func(*args, **kwargs): + t = time.ticks_us() + result = f(*args, **kwargs) + delta = time.ticks_diff(time.ticks_us(), t) + print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000)) + return result + return new_func -- 2.49.0