Question about order in lists
Darrell
news at dorb.com
Fri Aug 13 19:05:54 EDT 1999
You win.
Map is very fast in this case.
Although something intresting happend when I used
l1[:] to create l2
##################
import operator, time
def mapIt(l1, l2):
map( operator.add, l1,l2)
def loopIt(l1, l2):
x=[]
append=x.append
for i in range(len(l1)):
append(l1[i]+l2[i])
sz=1000000
l1=[]
for i in xrange(sz):l1.append(i)
if 0:
# Time1: 5.75 sec
# Time2: 27.70 sec
l2=[]
for i in xrange(sz):l2.append(i)
else:
# Odd when using these huge numbers
# This way of creating l2 ran faster ??
# Time1: 3.25 sec
# Time2: 28.50 sec
l2=l1[:]
t1=time.time()
mapIt(l1,l2)
print " Time1: %.2f sec"%(time.time()-t1)
t1=time.time()
loopIt(l1,l2)
print " Time2: %.2f sec"%(time.time()-t1)
####################
# Time1: 3.25 sec
# Time2: 28.50 sec
--Darrell
More information about the Python-list
mailing list