speed of map() vs. list comprehension vs. numpy vectorized function in python
- by mcstrother
I have a function foo(i) that takes an integer and takes a significant amount of time to execute. Will there be a significant performance difference between any of the following ways of initializing 'a':
a = [foo(i) for i in xrange(100)]
,
a = map(foo, range(100))
, and
vfoo = numpy.vectorize(foo)
vfoo(range(100))
? (I don't care whether the output is a list or a numpy array).
Is there some other better way of doing this?
Thanks.