Re: Optimising literals away

2010-09-01 Thread MRAB
On 01/09/2010 14:25, Lie Ryan wrote: On 09/01/10 17:06, Stefan Behnel wrote: MRAB, 31.08.2010 23:53: On 31/08/2010 21:18, Terry Reedy wrote: On 8/31/2010 12:33 PM, Aleksey wrote: On Aug 30, 10:38 pm, Tobias Weber wrote: Hi, whenever I type an "object literal" I'm unsure what optimisation wil

Re: Optimising literals away

2010-09-01 Thread Lie Ryan
On 09/01/10 17:06, Stefan Behnel wrote: > MRAB, 31.08.2010 23:53: >> On 31/08/2010 21:18, Terry Reedy wrote: >>> On 8/31/2010 12:33 PM, Aleksey wrote: On Aug 30, 10:38 pm, Tobias Weber wrote: > Hi, > whenever I type an "object literal" I'm unsure what optimisation > will do > t

Re: Optimising literals away

2010-09-01 Thread Stefan Behnel
MRAB, 31.08.2010 23:53: On 31/08/2010 21:18, Terry Reedy wrote: On 8/31/2010 12:33 PM, Aleksey wrote: On Aug 30, 10:38 pm, Tobias Weber wrote: Hi, whenever I type an "object literal" I'm unsure what optimisation will do to it. Optimizations are generally implentation dependent. CPython curre

Re: Optimising literals away

2010-08-31 Thread Cameron Simpson
On 31Aug2010 23:38, MRAB wrote: | On 31/08/2010 23:11, Cameron Simpson wrote: | >On 31Aug2010 22:53, MRAB wrote: | >| There's still the possibility of some optimisation. If the resulting | >| set is never stored anywhere (bound to a name, for example) then it | >| could be created once. When the

Re: Optimising literals away

2010-08-31 Thread MRAB
On 31/08/2010 23:11, Cameron Simpson wrote: On 31Aug2010 22:53, MRAB wrote: [...] |>>>def m(arg): |>>>if arg& set([1,2,3]): |> |>set() is a function call, not a literal. When m is called, who knows |>what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, |>which is much faster

Re: Optimising literals away

2010-08-31 Thread Cameron Simpson
On 31Aug2010 22:53, MRAB wrote: [...] | >>>def m(arg): | >>>if arg& set([1,2,3]): | > | >set() is a function call, not a literal. When m is called, who knows | >what 'set' will be bound to? In Py3, at least, you could write {1,2,3}, | >which is much faster as it avoids creating and deleting a list

Re: Optimising literals away

2010-08-31 Thread MRAB
On 31/08/2010 21:18, Terry Reedy wrote: On 8/31/2010 12:33 PM, Aleksey wrote: On Aug 30, 10:38 pm, Tobias Weber wrote: Hi, whenever I type an "object literal" I'm unsure what optimisation will do to it. Optimizations are generally implentation dependent. CPython currently creates numbers, str

Re: Optimising literals away

2010-08-31 Thread Terry Reedy
On 8/31/2010 12:33 PM, Aleksey wrote: On Aug 30, 10:38 pm, Tobias Weber wrote: Hi, whenever I type an "object literal" I'm unsure what optimisation will do to it. Optimizations are generally implentation dependent. CPython currently creates numbers, strings, and tuple literals just once. Mut

Re: Optimising literals away

2010-08-31 Thread Stefan Behnel
John Nagle, 31.08.2010 21:03: On 8/30/2010 8:38 AM, Tobias Weber wrote: whenever I type an "object literal" I'm unsure what optimisation will do to it. CPython is a "naive interpreter". It has almost no optimization. It doesn't even really comprehend "constants". This is an implementation prob

Re: Optimising literals away

2010-08-31 Thread John Nagle
On 8/30/2010 8:38 AM, Tobias Weber wrote: Hi, whenever I type an "object literal" I'm unsure what optimisation will do to it. CPython is a "naive interpreter". It has almost no optimization. It doesn't even really comprehend "constants". This is an implementation problem, not a language pro

Re: Optimising literals away

2010-08-31 Thread Aleksey
On Aug 30, 10:38 pm, Tobias Weber wrote: > Hi, > whenever I type an "object literal" I'm unsure what optimisation will do > to it. > > def m(arg): >   if arg & set([1,2,3]): >     return 4 > > Is the set created every time the method is called? What about a > frozenset? Or tuple vs list? After how

Re: Optimising literals away

2010-08-30 Thread Arnaud Delobelle
Tobias Weber writes: > Hi, > whenever I type an "object literal" I'm unsure what optimisation will do > to it. > > def m(arg): > if arg & set([1,2,3]): > return 4 > > Is the set created every time the method is called? What about a > frozenset? Or tuple vs list? After how many calls per s

Re: Optimising literals away

2010-08-30 Thread Benjamin Peterson
Tobias Weber gmx.net> writes: > > Hi, > whenever I type an "object literal" I'm unsure what optimisation will do > to it. > > def m(arg): > if arg & set([1,2,3]): > return 4 > > Is the set created every time the method is called? Yes, and the list. > What about a > frozenset? Yep.

Re: Optimising literals away

2010-08-30 Thread Thomas Jollans
On Monday 30 August 2010, it occurred to Tobias Weber to exclaim: > Hi, > whenever I type an "object literal" I'm unsure what optimisation will do > to it. > > def m(arg): > if arg & set([1,2,3]): > return 4 > > Is the set created every time the method is called? What about a > frozenset? O