Just wondering
Marco Mariani
marco at sferacarta.com
Fri May 15 08:21:03 EDT 2009
Gediminas Kregzde wrote:
> def doit(i):
> pass
>
> def main():
> a = [0] * 10000000
> 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 = time()
> a = [0] * 10000000
> for i in a:
> pass
> print "loop time: " + str(time() - t)
Here you do nothing but iterating 'i' over the 'a' list.
> main() # takes approximately 5x times longer than main2()
> main2()
>
> I'm wondering were is catch?
Function calls are not free in python. They cost a lot more than they do
in C, Delphi or other languages.
More information about the Python-list
mailing list