Created
December 22, 2023 14:04
-
-
Save ValentaTomas/7031b908229a51ce9ad3702378b983d9 to your computer and use it in GitHub Desktop.
Measure execution time of a function
This file contains 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
def stopwatch(): | |
def decorator(func): | |
def wrapper(*args, **kwargs): | |
start_time = time.time() | |
result = func(*args, **kwargs) | |
end_time = time.time() | |
elapsed_time = end_time - start_time | |
print(f"time taken {elapsed_time: 2f}") | |
return result | |
return wrapper | |
return decorator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment