Just wondering

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri May 15 14:58:08 CEST 2009


Gediminas Kregzde a écrit :
> 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 

Why should it be a bug ?

> for about 5 times,

read below for comments on your benchmark.

> when using huge amounts of data.
> It is needed to perform some operations, not to return data.

Then don't use map. You're uselessly building a new list (which takes 
time *and* eats RAM - so on 'huge' dataset, this might even make your 
system start swapping).



> I'm adding sample code:
> from time import time

The correct way to time code is to use the timeit module.

> 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

Your benchmark is screwed. In the first case, you call doit() X times 
(with X = len(a)), while in the second case you don't call it at all.




More information about the Python-list mailing list