speed of map() vs. list comprehension vs. numpy vectorized function in python

Posted by mcstrother on Stack Overflow See other posts from Stack Overflow or by mcstrother
Published on 2010-04-24T05:16:33Z Indexed on 2010/04/24 5:23 UTC
Read the original article Hit count: 198

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy