#!/usr/bin/env python # coding: utf-8 # > This is one of the 100 recipes of the [IPython Cookbook](http://ipython-books.github.io/), the definitive guide to high-performance scientific computing and data science in Python. # # # 4.1. Evaluating the time taken by a statement in IPython # In[ ]: n = 100000 # In[ ]: get_ipython().run_line_magic('timeit', 'sum([1. / i**2 for i in range(1, n)])') # In[ ]: get_ipython().run_cell_magic('timeit', 's = 0.', 'for i in range(1, n):\n s += 1. / i**2\n') # In[ ]: import numpy as np # In[ ]: get_ipython().run_line_magic('timeit', 'np.sum(1. / np.arange(1., n) ** 2)') # > You'll find all the explanations, figures, references, and much more in the book (to be released later this summer). # # > [IPython Cookbook](http://ipython-books.github.io/), by [Cyrille Rossant](http://cyrille.rossant.net), Packt Publishing, 2014 (500 pages).