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

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