Advantage of the array module over lists?

sturlamolden sturlamolden at yahoo.no
Sun Mar 16 14:55:31 EDT 2008


On 13 Mar, 20:40, Tobiah <t... at tobiah.org> wrote:
> I checked out the array module today.  It claims that
> arrays are 'efficient'.  I figured that this must mean
> that they are faster than lists, but this doesn't seem
> to be the case:
>
> ################ one.py ##############
> import array
>
> a = array.array('i')
>
> for x in xrange(10000000):
>         a.append(x)


Lists are better optimized for appending to the end. Python lists are
implemented as arrays of pointers, with a few empty slots at the
end.

Arrays are contigous memory buffers. They provide faster read-write
access, particularly for chunks of data, but are slower at resizing.

I never use the array module, as NumPy is superior.













More information about the Python-list mailing list