Skip to content

Instantly share code, notes, and snippets.

View vincentwyshan's full-sized avatar

Vincent Wen vincentwyshan

  • Shanghai
View GitHub Profile
@vincentwyshan
vincentwyshan / profiling_decorator.py
Last active February 26, 2024 15:30 — forked from nealtodd/decorator.py
Python profiling decorator
"""
Python decorator for profiling a function using cProfile. Stats are output to wherever print statements would
normally go to, e.g. stdout or a log file. Can be used with Django view functions.
pstats' sort and print arguments can be supplied to the decorator. The default is to sort cumulatively and
list to first 10 lines.
See http://docs.python.org/library/profile.html#instant-user-s-manual for details on pstats sort and print arguments.
cProfile is a standard module in most python distributions. pstats is also in many but not all. If pstats doesn't