Last active
September 3, 2021 12:25
-
-
Save carlosperate/49c1605827e6912ee61d8a1a992115f8 to your computer and use it in GitHub Desktop.
Timing functions in MicroPython via decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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