Created
August 28, 2018 06:23
-
-
Save mezhaka/6198245f36762e5d332a746e8454e5cc to your computer and use it in GitHub Desktop.
Printing profiling stats example
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
#!/usr/bin/env python3.4 | |
import cProfile | |
import pstats | |
def first(): | |
pass | |
def second(): | |
for _ in range(100000): | |
first() | |
def doit(): | |
for _ in range(100000): | |
first() | |
for _ in range(2): | |
second() | |
def profile(): | |
profile = cProfile.Profile() | |
profile.enable() | |
doit() | |
profile.disable() | |
return pstats.Stats(profile) | |
if __name__ == '__main__': | |
s = profile() | |
# print everything | |
s.sort_stats('cumulative').print_stats() | |
# print what second called through doit | |
s.print_callees('doit').print_callees('second') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment