Skip to content

Instantly share code, notes, and snippets.

@mallipeddi
Last active December 19, 2015 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mallipeddi/5923494 to your computer and use it in GitHub Desktop.
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.
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