[ create a new paste ] login | about

Link: http://codepad.org/e9pOMxV8    [ raw code | output | fork ]

Python, pasted on Mar 8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from time import time
import itertools

values = xrange(10000000)

st = time()
for value in (value for value in values if value > 2):
    pass
print time() - st #3.91020894051

st = time()
for value in filter(lambda x: x > 2, values):
    pass
print time() - st #5.53530097008

st = time()
for value in itertools.ifilter(lambda x: x > 2, values):
    pass
print time() - st #5.0817360878


Output:
1
Timeout


Create a new paste based on this one


Comments: