Created
September 16, 2013 20:46
-
-
Save philippstroehle/6586379 to your computer and use it in GitHub Desktop.
Profiling runtime and memory
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
@profile # python -m memory_profiler example.py | |
def my_func(): | |
a = [1] * (10 ** 6) | |
b = [2] * (2 * 10 ** 7) | |
del b | |
return a | |
if __name__ == '__main__': | |
my_func() |
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
if False: | |
main() | |
else: | |
import cProfile | |
# call method main and log results to profile.log | |
cProfile.run('main()', 'profile.log') | |
import pstats | |
# used to analyze stats | |
p = pstats.Stats('profile.log') | |
# return the 100 most time consuming methods | |
p.sort_stats('time').print_stats(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment