In [1]:
from __future__ import print_function
Here we import our own module called myprofile (we have it in the same directory as this notebook)
In [2]:
import myprofile
We have a docstring at the top -- the comments there are what appear when we ask for help
In [3]:
help(myprofile)
This module simply provides a way to time routines (python and ipython have built-in methods for this too)
In [4]:
t = myprofile.Timer("main loop")
t.begin()
sum = 0.0
for n in range(1000):
sum += n**2
t.end()
myprofile.time_report()
print(sum)
In the file myprofile.py, you will see a block of code under
if __name__ == "__main__":
That code is executed if the file is run directly, either from the commandline as:
python myprofile.py
for through the %run magic
In [5]:
%run myprofile
In [ ]:
In [ ]:
In [ ]: