Last active
August 29, 2015 14:14
-
-
Save avoiney/243000f5599bc17b4daa to your computer and use it in GitHub Desktop.
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
""" A decorator to easily use cProfile on function """ | |
import cProfile | |
def profiler(sort=-1, use_globals=False, use_locals=True): | |
def decr(func): | |
def wrp(*args, **kwargs): | |
g = globals() if use_globals else None | |
l = locals() if use_locals else None | |
cProfile.runctx("func(*args, **kwargs)", g, l, sort=sort) | |
return func(*args, **kwargs) | |
return wrp | |
return decr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment