Re: genexp performance problem?



Fredrik Lundh wrote:

I found this strange:

python -mtimeit "sum(int(L) for L in xrange(3000))"
100 loops, best of 3: 5.04 msec per loop

python -mtimeit "import itertools; sum(itertools.imap(int,
xrange(3000)))" 100 loops, best of 3: 3.6 msec per loop

I thought the two constructs could achieve the same speed.

hint: how many times to the interpreter have to look up the names
"int"
and "L" in the two examples ?

Ah right, thanks!
--
Giovanni Bajo


.



Relevant Pages

  • Re: Christmas time is here
    ... | Python is popular, though the for syntax is a little unusual, ... | Ruby is another language that is used in Webdevelopment. ... Its for loops ...
    (sci.physics)
  • Re: Christmas time is here
    ... Python is popular, though the for syntax is a little unusual, ... Ruby is another language that is used in Webdevelopment. ... Its for loops ...
    (sci.physics)
  • Re: Christmas time is here
    ... Python is popular, though the for syntax is a little unusual, ... Ruby is another language that is used in Webdevelopment. ... Its for loops ...
    (sci.physics)
  • Re: Christmas time is here
    ... |> Python is popular, though the for syntax is a little unusual, ... |> Ruby is another language that is used in Webdevelopment. ... Its for loops ...
    (sci.physics)
  • Re: Christmas time is here
    ... |> Python is popular, though the for syntax is a little unusual, ... |> Ruby is another language that is used in Webdevelopment. ... Its for loops ...
    (sci.physics)