timeit and timeit in IPython

suggest change

Profiling string concatenation:

In [1]: import string

In [2]: %%timeit s=""; long_list=list(string.ascii_letters)*50
  ....: for substring in long_list:
  ....:   s+=substring
  ....:
1000 loops, best of 3: 570 us per loop

In [3]: %%timeit long_list=list(string.ascii_letters)*50
  ....: s="".join(long_list)
  ....:
100000 loops, best of 3: 16.1 us per loop

Profiling loops over iterables and lists:

In [4]: %timeit for i in range(100000):pass
100 loops, best of 3: 2.82 ms per loop

In [5]: %timeit for i in list(range(100000)):pass
100 loops, best of 3: 3.95 ms per loop

This is an old IPython transcript, and the times depend on the machine. IPython is not installed here, so the “best of 3” default was not rechecked.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents