from timeit import Timer Timer len list xrange 20000 timeit 3000 Timer

1
2
3
4
>>> from timeit import Timer
>>> Timer('len(list(xrange(2, 20000)))').timeit(3000), Timer('iter(xrange(2, 20000)).__length_hint__()').timeit(3000)
(1.5682804658133946, 0.0029490479935319058)
>>>