There are several IPython Notebook magic commands that are specially helpful at the moment of profiling code.

%timeit for line-magic and file magic command to create a simple module.

%%file test_mprun.py
def some_function():
	...
 
# ---
 
from test_mprun import some_function
 
# ---
 
%mprun -f some_function some_function()

Sources