Skip to content

Instantly share code, notes, and snippets.

@ValentaTomas
Created December 22, 2023 14:04
Show Gist options
  • Save ValentaTomas/7031b908229a51ce9ad3702378b983d9 to your computer and use it in GitHub Desktop.
Save ValentaTomas/7031b908229a51ce9ad3702378b983d9 to your computer and use it in GitHub Desktop.
Measure execution time of a function
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