Create a gist now

Instantly share code, notes, and snippets.

@danriti /README.md
Last active Jul 20, 2017

What would you like to do?
Line Profiling in Python
#!/usr/bin/python
from time import sleep
def so_slow(bar):
""" Simulate a slow function. """
sleep(5)
return bar
@profile
def its_time_for_the_calculator(foo):
""" It's time for the calculator. """
if not isinstance(foo, int):
return None
a = []
for i in xrange(foo):
a.append(i)
b = so_slow(a)
c = 0
for i in xrange(foo):
c += i
return None
def main():
print its_time_for_the_calculator(100000)
if __name__ == "__main__":
main()

ckarany commented Feb 11, 2015

Where is "@Profile" decorator defined?

neara commented Jul 13, 2015

exactly

You have to call kernprof with the -l flag for the @Profile decorator to be recognized

What is kernprof.py?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment