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)
for x in a:
a[x] += 1
############### # two.py ##############
a = []
for x in xrange(10000000 ):
a.append(x)
for x in a:
a[x] += 1
############### ############### ########
ktops:toby:pyte sttime python one.py; time python two.py
real 0m28.116s
user 0m17.504s
sys 0m10.435s
real 0m23.026s
user 0m13.027s
sys 0m9.777s
Perhaps the only advantage is that they take less memory
to store a large number of items? It would seem then, that
'economical' might have been a better choice of word than
'efficient'.
Thanks,
Toby
--
Posted via a free Usenet account from http://www.teranews.com
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)
for x in a:
a[x] += 1
############### # two.py ##############
a = []
for x in xrange(10000000 ):
a.append(x)
for x in a:
a[x] += 1
############### ############### ########
ktops:toby:pyte sttime python one.py; time python two.py
real 0m28.116s
user 0m17.504s
sys 0m10.435s
real 0m23.026s
user 0m13.027s
sys 0m9.777s
Perhaps the only advantage is that they take less memory
to store a large number of items? It would seem then, that
'economical' might have been a better choice of word than
'efficient'.
Thanks,
Toby
--
Posted via a free Usenet account from http://www.teranews.com
Comment