Created
May 22, 2018 15:51
-
-
Save Ryanb58/a44d4a3742b3c53a95b0eb60c1a2ddca to your computer and use it in GitHub Desktop.
Profile a section of code in python.
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
import time | |
import cProfile, pstats, StringIO | |
import os | |
import shutil | |
import tempfile | |
start_time = time.time() | |
pr = cProfile.Profile() | |
pr.enable() | |
# Insert function you want called here. | |
pr.disable() | |
sortby = 'cumulative' | |
fd, tmpfile = tempfile.mkstemp() | |
os.close(fd) | |
pr.dump_stats(tmpfile) | |
shutil.move(tmpfile, '/usr/local/smartfile/www/CPROFILE') | |
print("Function took {} seconds.".format(time.time() - start_time)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment