Learning Scientific Programming with Python (2nd edition)

P5.1.1: The IPython %timeit magic

Question P5.1.1

Improve on the algorithm to find the number of factors of an integer given in Section 5.1.3 of the book by (a) looping the trial factor, i, up to no greater than the square root of n (why is it not necessary to test values of i greater than this?), and (b) using a generator (see Section 4.3.5). Compare the execution speed of these alternatives using the %timeit IPython magic.