Skip to content

Instantly share code, notes, and snippets.

@adambarthelson
Created April 13, 2013 00:47
Show Gist options
  • Save adambarthelson/5376300 to your computer and use it in GitHub Desktop.
Save adambarthelson/5376300 to your computer and use it in GitHub Desktop.
Efficiency breakdown of Python files.
import os
import pstats
def testeff(path):
try:
os.remove('rep.prof')
except:
os.system('python -m cProfile -o rep.prof {}'.format(path))
p = pstats.Stats('rep.prof')
p.sort_stats('cumulative').print_stats(10)
os.remove('rep.prof')
else:
os.system('python -m cProfile -o rep.prof {}'.format(path))
p = pstats.Stats('rep.prof')
p.sort_stats('cumulative').print_stats(10)
os.remove('rep.prof')
path = str(raw_input('File path: '))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment