Just wondering

Jaime Fernandez del Rio jaime.frio at gmail.com
Fri May 15 08:27:25 EDT 2009


map is creating a new list of 10,000,000 items, not modifying the
values inside list a. That's probably where your time difference comes
from...

Jaime

On Fri, May 15, 2009 at 1:56 PM, Gediminas Kregzde
<gediminas.kregzde at gmail.com> wrote:
> Hello,
>
> I'm Vilnius college II degree student and last semester our teacher
> introduced us to python
> I've used to program with Delphi, so I very fast adopted to python
>
> Now I'm developing cross platform program and use huge amounts of
> data. Program is needed to run as fast as it coud. I've read all tips
> about geting performance, but got 1 bug: map function is slower than
> for loop for about 5 times, when using huge amounts of data.
> It is needed to perform some operations, not to return data.
>
> I'm adding sample code:
> from time import time
>
> def doit(i):
>   pass
>
> def main():
>   a = [0] * 10000000
>   t = time()
>   map(doit, a)
>   print "map time: " + str(time() - t)
>
> def main2():
>   t = time()
>   a = [0] * 10000000
>   for i in a:
>       pass
>   print "loop time: " + str(time() - t)
>
> main()  # takes approximately 5x times longer than main2()
> main2()
>
> I'm wondering were is catch?
>
> I'm using python 2.6 on windows xp sp2 machine
>
> P.S. Sorry for my broken English
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
(\__/)
( O.o)
( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus
planes de dominación mundial.



More information about the Python-list mailing list