This is relating to the following: (In Python Code)
for i in object:
doSomething(i)
versus
map(doSomething, object)
>
EDIT: I didn't realize that map equals itertools.imap after python 3.0. So the conclusion here may not be correct. I'll re-run the test on python 2.6 tomorrow and post result.
If doSomething is very "tiny", map can be a lot faster than for loop or a list-comprehension:
# Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
from timeit import timeit
do = lambda i: i+1
def _for():
for i in range(1000):
do(i)
def _map():
map(do, range(1000))
def _list():
[do(i) for i in range(1000)]
timeit(_for, number=10000) # 2.5515936921388516
timeit(_map, number=10000) # 0.010167432629884843
timeit(_list, number=10000) # 3.090125159839033
This is because map is written in C, while for loop and list-comprehension run in python virtual machine.