On 5/18/2011 10:19 AM, Nadeem Vawda wrote:
> I'm not sure why you would encounter code like that in the first place.
> Surely any code of the form:
>
> ''.join(c for c in my_string)
>
> would just return my_string? Or am I missing something?
You might more-or-less legitimately encounter it if t
On Wed, May 18, 2011 at 2:34 PM, Victor Stinner
wrote:
> Le mercredi 18 mai 2011 à 16:19 +0200, Nadeem Vawda a écrit :
>> I'm not sure why you would encounter code like that in the first place.
>
> Well, I found the STORE_FAST/LOAD_FAST "issue" while trying to optimize
> the this module which reim
Victor Stinner wrote:
I suppose that you have the current value of range(1) on the stack:
DUP_TOP; BINARY_MULTIPLY; gives you the square. You don't need the x
variable (LOAD_FAST/STORE_FAST).
That seems far too special-purpose to be worth it to me.
--
Greg
Le mercredi 18 mai 2011 à 21:44 -0400, Terry Reedy a écrit :
> On 5/18/2011 5:34 PM, Victor Stinner wrote:
>
> You initial example gave me the impression that the issue has something
> to do with join in particular, or even comprehensions in particular. It
> is really about for loops.
>
> >>>
Le jeudi 19 mai 2011 à 10:47 +1200, Greg Ewing a écrit :
> Victor Stinner wrote:
>
> >squares = (x*x for x in range(1))
>
> What bytecode would you optimise that into?
I suppose that you have the current value of range(1) on the stack:
DUP_TOP; BINARY_MULTIPLY; gives you the square.
On Thu, May 19, 2011 at 7:34 AM, Victor Stinner
wrote:
> But it is slower whereas I read somewhere than generators are faster
> than loops.
Are you sure it wasn't that generator expressions can be faster than
list comprehensions (if the memory savings are significant)?
Or that a reduction functi
On 5/18/2011 5:37 PM, Amaury Forgeot d'Arc wrote:
Hi,
2011/5/18 Terry Reedy:
On 5/18/2011 10:19 AM, Nadeem Vawda wrote:
I'm not sure why you would encounter code like that in the first place.
Surely any code of the form:
''.join(c for c in my_string)
would just return my_string? Or am
On 5/18/2011 5:34 PM, Victor Stinner wrote:
You initial example gave me the impression that the issue has something
to do with join in particular, or even comprehensions in particular. It
is really about for loops.
squares = (x*x for x in range(1))
>>> dis('for x in range(3): y = x
Victor Stinner wrote:
squares = (x*x for x in range(1))
What bytecode would you optimise that into?
--
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.
Hi,
2011/5/18 Terry Reedy :
> On 5/18/2011 10:19 AM, Nadeem Vawda wrote:
>
>> I'm not sure why you would encounter code like that in the first place.
>> Surely any code of the form:
>>
>> ''.join(c for c in my_string)
>>
>> would just return my_string? Or am I missing something?
>
> Good quest
Le mercredi 18 mai 2011 à 16:19 +0200, Nadeem Vawda a écrit :
> I'm not sure why you would encounter code like that in the first place.
Well, I found the STORE_FAST/LOAD_FAST "issue" while trying to optimize
the this module which reimplements rot13 using a dict in Python 3:
d = {}
for c in (65, 9
On 5/18/2011 10:19 AM, Nadeem Vawda wrote:
I'm not sure why you would encounter code like that in the first place.
Surely any code of the form:
''.join(c for c in my_string)
would just return my_string? Or am I missing something?
Good question. Anything useful like "'-'.join(c for c in
On Wed, May 18, 2011 at 2:21 PM, Victor Stinner
wrote:
> ''.join(c for c in 'abc') and ''.join([c for c in 'abc']) do create a
> temporary c variable.
I'm not sure why you would encounter code like that in the first place.
Surely any code of the form:
''.join(c for c in my_string)
would jus
On Wed, May 18, 2011 at 10:21 PM, Victor Stinner
wrote:
> What do you think? Is it useless and/or stupid?
I wouldn't call it useless or stupid - merely "lost in the noise". In
small cases, I expect it would be swamped completely by the high fixed
overhead of entering the new scope and in all gene
2011/5/18 Victor Stinner :
> Hi,
>
> ''.join(c for c in 'abc') and ''.join([c for c in 'abc']) do create a
> temporary c variable. In this case, the variable is useless and requires
> two opcodes: STORE_FAST(c), LOAD_FAST(c). The variable is not available
> outside the list comprehension/generator.
Hi,
''.join(c for c in 'abc') and ''.join([c for c in 'abc']) do create a
temporary c variable. In this case, the variable is useless and requires
two opcodes: STORE_FAST(c), LOAD_FAST(c). The variable is not available
outside the list comprehension/generator.
I would like to remove the variable
16 matches
Mail list logo