Skip to content

Instantly share code, notes, and snippets.

@elleryq
Forked from myusuf3/profile.py
Created September 6, 2017 01:54
Show Gist options
  • Save elleryq/54405e564f14d66876debd4d3929fec0 to your computer and use it in GitHub Desktop.
Save elleryq/54405e564f14d66876debd4d3929fec0 to your computer and use it in GitHub Desktop.
Simple little profiling decorator in python.
import cProfile
def profile_this(fn):
def profiled_fn(*args, **kwargs):
# name for profile dump
fpath = fn.__name__ + '.profile'
prof = cProfile.Profile()
ret = prof.runcall(fn, *args, **kwargs)
prof.dump_stats(fpath)
return ret
return profiled_fn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment