X-Git-Url: https://git.ayoreis.com/hackapet/Adafruit_Blinka.git/blobdiff_plain/f4f44cf730870773ff87242037bf7fd5f6acd8cd..5c2512abe5fa4f633afa94c742f3cd6bbf24c401:/test/src/testing/profiling/__init__.py diff --git a/test/src/testing/profiling/__init__.py b/test/src/testing/profiling/__init__.py new file mode 100644 index 0000000..fce14a4 --- /dev/null +++ b/test/src/testing/profiling/__init__.py @@ -0,0 +1,11 @@ +def time_function(f): + import utime + """From http://docs.micropython.org/en/latest/esp8266/reference/speed_python.html""" + myname = str(f).split(' ')[1] + def new_func(*args, **kwargs): + t = utime.ticks_us() + result = f(*args, **kwargs) + delta = utime.ticks_diff(utime.ticks_us(), t) + print('Function {} Time = {:6.3f}ms'.format(myname, delta/1000)) + return result + return new_func