!time python slow_functions.py import slow_functions import time t1 = time.time() result = slow_functions.main() t2 = time.time() print 'slow_functions.main took {} seconds'.format(t2 - t1) %run -t slow_functions.py %timeit slow_functions.main() import numpy as np from numpy import interp from scipy.interpolate import interp1d x = np.linspace(0, 2*np.pi, 10) y = np.sin(x) xvals = np.linspace(0, 2*np.pi, 50) #scipy f = interp1d(x, y) %timeit f(xvals) # numpy %timeit interp(xvals, x, y) scipy_vals = f(xvals) numpy_vals = interp(xvals, x, y) print np.allclose(scipy_vals, numpy_vals) !python -m cProfile slow_functions.py !python -m cProfile -o slow_functions.prof slow_functions.py import pstats stats = pstats.Stats('slow_functions.prof') stats.print_stats() stats.sort_stats('cum').print_stats() stats.sort_stats('time').print_stats() stats.sort_stats('time').print_stats(3) stats.sort_stats('cum').print_stats(r'func\d') stats.sort_stats('time').print_stats(r'func\d', 3) %prun slow_functions.main() %prun -D slow_functions_main.prof slow_functions.main() stats = %prun -q -r f(xvals) # work around a bug in IPython import sys stats.stream = sys.stdout stats.sort_stats('time').print_stats(10) %%prun f(xvals) interp(xvals, x, y) %load_ext line_profiler %lprun -f slow_functions.main slow_functions.main() %lprun -f slow_functions.func5 slow_functions.main() %lprun -f f.__call__ f(xvals) %prun -q -D scipy_interp.prof f(xvals) %prun -q -D numpy_interp.prof interp(xvals, x, y)