Skip to content

Instantly share code, notes, and snippets.

@Jan-Zeiseweis
Last active September 18, 2019 10:18
Show Gist options
  • Save Jan-Zeiseweis/0f793c68cdc60daccce9dae6889633ce to your computer and use it in GitHub Desktop.
Save Jan-Zeiseweis/0f793c68cdc60daccce9dae6889633ce to your computer and use it in GitHub Desktop.
import cProfile
from datetime import datetime
def profileit(func):
def wrapper(*args, **kwargs):
datafn = f"{func.__name__}_{datetime.now().strftime('%Y%m%d_%H%M%S_%f')}.profile"
prof = cProfile.Profile()
retval = prof.runcall(func, *args, **kwargs)
prof.dump_stats(datafn)
return retval
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment