Skip to content

Instantly share code, notes, and snippets.

@h3ct0rjs
Created September 27, 2023 02:49
Show Gist options
  • Save h3ct0rjs/f55e1540e3e601bde04b7c87246a939a to your computer and use it in GitHub Desktop.
Save h3ct0rjs/f55e1540e3e601bde04b7c87246a939a to your computer and use it in GitHub Desktop.
import time
# Define a decorator function to measure execution time
def timing_decorator(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
execution_time = end_time - start_time
print(f"{func.__name__} took {execution_time:.2f} seconds to execute.")
return result
return wrapper
# Apply the timing decorator to a function
@timing_decorator
def slow_function():
time.sleep(2) # Simulate a slow operation
# Call the decorated function
slow_function()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment