Re: Just wondering

2009-05-18 Thread norseman
Dave Angel wrote: norseman wrote: div class=moz-text-flowed style=font-family: -moz-fixedMarco Mariani wrote: Gediminas Kregzde wrote: def doit(i): pass def main(): a = [0] * 1000 t = time() map(doit, a) print map time: + str(time() - t) Here you are calling a

Just wondering

2009-05-15 Thread Gediminas Kregzde
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

Re: Just wondering

2009-05-15 Thread bearophileHUGS
Gediminas Kregzde: 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. Then you are using map() for the wrong purpose. map() purpose is to build a list of things. Use a for loop. Bye, bearophile

Re: Just wondering

2009-05-15 Thread Stef Mientki
and this, while it's realy doing something is even 4 times faster than main2 ;-) And if you only need integers, it can be even faster. def main3(): from numpy import zeros t = time() a = zeros ( 1000 ) b = a + 3.14 print loop time: + str(time() - t) cheers, Stef Gediminas

Re: Just wondering

2009-05-15 Thread Marco Mariani
Gediminas Kregzde wrote: def doit(i): pass def main(): a = [0] * 1000 t = time() map(doit, a) print map time: + str(time() - t) Here you are calling a function ten million times, build a list with of ten million None results, then throw it away. def main2(): t =

Re: Just wondering

2009-05-15 Thread Jaime Fernandez del Rio
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.kreg...@gmail.com wrote: Hello, I'm Vilnius college II degree student and last

Re: Just wondering

2009-05-15 Thread Peter Otten
Gediminas Kregzde wrote: 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.

Re: Just wondering

2009-05-15 Thread Jaime Fernandez del Rio
(1) building another throwaway list and (2) function call overhead for calling doit() You can avoid (1) by using filter() instead of map() Are you sure of this? My python returns, when asked for help(filter) : Help on built-in function filter in module __builtin__: filter(...)

Re: Just wondering

2009-05-15 Thread Bruno Desthuilliers
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

Re: Just wondering

2009-05-15 Thread Peter Otten
Jaime Fernandez del Rio wrote: (1) building another throwaway list and (2) function call overhead for calling doit() You can avoid (1) by using filter() instead of map() Are you sure of this? I'm afraid there is no builtin function to do an inplace modification of a sequence... You

Re: Just wondering

2009-05-15 Thread norseman
Gediminas Kregzde 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

Re: Just wondering

2009-05-15 Thread norseman
Marco Mariani wrote: Gediminas Kregzde wrote: def doit(i): pass def main(): a = [0] * 1000 t = time() map(doit, a) print map time: + str(time() - t) Here you are calling a function ten million times, build a list with of ten million None results, then throw it away.

Re: Just wondering

2009-05-15 Thread Dave Angel
norseman wrote: div class=moz-text-flowed style=font-family: -moz-fixedMarco Mariani wrote: Gediminas Kregzde wrote: def doit(i): pass def main(): a = [0] * 1000 t = time() map(doit, a) print map time: + str(time() - t) Here you are calling a function ten million