Created
May 29, 2019 12:50
-
-
Save richardARPANET/fd4aaaf074d364eefe138b839683277b to your computer and use it in GitHub Desktop.
Profile any Python function easily.
This file contains hidden or 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
from functools import wraps | |
import cProfile | |
def profileit(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): | |
profile = cProfile.Profile() | |
return_value = profile.runcall(func, *args, **kwargs) | |
profile.dump_stats(f'{func.__name__}.profile') | |
return return_value | |
return wrapper | |
# then read the output with snakeviz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment