Last active
December 19, 2015 08:09
-
-
Save mallipeddi/5923494 to your computer and use it in GitHub Desktop.
yappi overhead is proportional to the number of function calls in the codepath. So yappi could penalize some code paths more than some other code paths.
This file contains hidden or 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 yappi | |
import time | |
yappi.set_clock_type("cpu") | |
def foo(n): | |
s = 0 | |
for i in xrange(n): | |
s += n*n | |
def bar(s,n): | |
return s + n*n | |
def baz(n): | |
s = 0 | |
for i in xrange(n): | |
s = bar(s,n) | |
def profile_foo(n): | |
yappi.start(True) | |
foo(n) | |
yappi.stop() | |
yappi.clear_stats() | |
def profile_baz(n): | |
yappi.start(True) | |
baz(n) | |
yappi.stop() | |
yappi.clear_stats() | |
def time_foo(n): | |
start = time.time() | |
profile_foo(n) | |
print time.time() - start | |
def time_baz(n): | |
start = time.time() | |
profile_baz(n) | |
print time.time() - start | |
def time_pure_foo(n): | |
start = time.time() | |
foo(n) | |
print time.time() - start | |
def time_pure_baz(n): | |
start = time.time() | |
baz(n) | |
print time.time() - start | |
time_baz(50000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment