Threading/map question
Anand
anandpillai6 at yahoo.com
Thu Dec 5 09:43:35 EST 2002
A question about function performance.
I have a list of integers on which an operation is to be performed,
say an addition or subtraction. Since the list is huge (len >= 100000)
,I can do it in two ways (I thought)
Using map,
#ldata is the list
global ldataout=[]
ldataout=map(function_to_call, ldata)
#Function to call on each member of the list
def function_to_call(self, val):
return 255 - val
def function_to_call2(self):
for x in range(0, len(ldata)):
ldataout[x] = 255 - ldata[x]
#Using a thread and waiting for it to complete the work
t=threading.Thread(None,function_to_call2, "Func", (val,))
t.start()
t.join() #suspend the calling thread
I found that the thread solution takes lesser time than the map
solution. Can this be a general approach for all data structures in python
or does it apply only to lists.
Thanks
Anand
More information about the Python-list
mailing list