[ create a new paste ] login | about

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

Python, pasted on Mar 8:
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 #1.90100002289

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

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

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


Output:
1
Timeout


Create a new paste based on this one


Comments: