I am confronted to a weird situation that I can't explain. Here is my test timing the generation of a large list of tuples:
In [1]: def get_list_of_tuples():
...: return [(i,) for i in range(10**6)]
...:
In [2]: %time res = get_list_of_tuples()
CPU times: user 0.93 s, sys: 0.08 s, total: 1.01 s
Wall time: 0.98 s
In [3]: %timeit res = get_list_of_tuples()
1 loops, best of 3: 92.1 ms per loop
As you can see, the generation of this large list of tuples takes just below a second. timeit reports the execution time to be around 0.1 second. Why is there such a big difference in the two reports?
(Tested on IPython 0.11, Python 2.6.5.)
%time
or%timeit
, but my guess would be that%time
repeats the timing test 10 times. – Telluridefor i in range(3): %time res=get_list_of_tuples()
get you? For this reason, it is normal for %timeit to report smaller numbers (I typically see ~2x), but 10x is a lot. I don't suppose you are on Windows? – Coloratura