Threading/map question

Michael Hudson mwh at python.net
Thu Dec 5 10:45:54 EST 2002


anandpillai6 at yahoo.com (Anand) writes:

> 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)

OK.

>  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.

Asking if threading or map gives better performance seems to me like
asking whether mashed potatoes or tofu are better at keeping one dry.

However, 

    ldataout = [None]*len(ldatain)
    for i in range(len(ldatain)):
        ldataout[i] = 255 - ldatain[i]

is likely to be quicker than

    ldataout = map(lambda x: 255 - x, ldatain)

because you don't have to take a trip through the function call
machinery for each element of the list in the first case.

Cheers,
M.

-- 
  The ultimate laziness is not using Perl.  That saves you so much
  work you wouldn't believe it if you had never tried it.
                                        -- Erik Naggum, comp.lang.lisp



More information about the Python-list mailing list