Anonymous     Text only     14 Oct 2008    
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
In [7]: def _while(x):
...: n = 0
...: while n < x:
...: n += 1
...:
In [8]: def _for(x):
...: for i in xrange(x):
...: pass
...:
In [10]: %timeit _while(100)
100000 loops, best of 3: 20.3 µs per loop
In [11]: %timeit _for(100)
100000 loops, best of 3: 7.93 µs per loop