Skip to content

Instantly share code, notes, and snippets.

@carlosperate
Last active September 3, 2021 12:25
Show Gist options
  • Save carlosperate/49c1605827e6912ee61d8a1a992115f8 to your computer and use it in GitHub Desktop.
Save carlosperate/49c1605827e6912ee61d8a1a992115f8 to your computer and use it in GitHub Desktop.
Timing functions in MicroPython via decorator
import time
def timed_function(f, *args, **kwargs):
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}us".format(delta))
return result
return new_func
@timed_function
def test_me():
for x in range(100):
result = 121 * x + 100
return result
test_me()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment