Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-22 Thread Andrew MacIntyre
Fredrik Lundh wrote: it could be worth expanding them to "if x == 1 or x == 2 or x == 3:" though... C:\>timeit -s "a = 1" "if a in (1, 2, 3): pass" 1000 loops, best of 3: 0.11 usec per loop C:\>timeit -s "a = 1" "if a == 1 or a == 2 or a == 3: pass" 1000 loops, best of 3: 0.0691 usec pe

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-19 Thread Aahz
On Sat, Feb 19, 2005, "Martin v. L?wis" wrote: > Fredrik Lundh wrote: >> >>I'd say that this explains why it would still make sense to let the code >>generator change >>"x in (a, b, c)" to "x == a or x == b or x == c", as long as a, b, and c >>are all integers. > > How often does that happen in

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-19 Thread Martin v. Löwis
Fredrik Lundh wrote: I'd say that this explains why it would still make sense to let the code generator change "x in (a, b, c)" to "x == a or x == b or x == c", as long as a, b, and c are all integers. How often does that happen in real code? Regards, Martin __

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Phillip J. Eby
At 04:45 PM 2/18/05 +0100, Fredrik Lundh wrote: Phillip J. Eby wrote: >>Only contains expressions are translated: >> >> "if x in [1,2,3]" >> >>currently turns into: >> >> "if x in (1,2,3)" >> >>and I'm proposing that it go one step further: >> >> "if x in Seachset([1,2,3])" > > ISTM tha

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Skip Montanaro
>> > Raymond then >> translated >> > >> > for x in [1,2,3]: >> > >> > to >> > >> > for x in frozenset([1,2,3]): Raymond> That's not right. for-statements are not touched. Thanks for the correction. My apologies for the misstep. Skip

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Phillip J. Eby
At 10:15 AM 2/18/05 -0500, Raymond Hettinger wrote: Only contains expressions are translated: "if x in [1,2,3]" currently turns into: "if x in (1,2,3)" and I'm proposing that it go one step further: "if x in Seachset([1,2,3])" ISTM that whenever I use a constant in-list like that, it's

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> > Raymond then > translated > > > > for x in [1,2,3]: > > > > to > > > > for x in frozenset([1,2,3]): That's not right. for-statements are not touched. > I may be missing something here (didn't follow the whole thread) but > those two are not functionally equal. > The docstring on fro

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Irmen de Jong
Skip Montanaro wrote: I suggested that since the standard library code is commonly used as an example of basic Python principles (that's probably not the right word), it should uphold that ideal tuple/list distinction. Raymond then translated for x in [1,2,3]: to for x in frozenset([1,2,3]

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
> I'm unclear why the list in "for x in [1,2,3]" or "if x not in [1,2,3]" > can't fairly easily be recognized as a constant and just be placed in the > constants array. That part got done (at least for the if-statement). The question is whether the type transformation idea should be carried a st

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Skip Montanaro
>> Based on some ideas from Skip, I had tried transforming the likes of >> "x in (1,2,3)" into "x in frozenset([1,2,3])" Fredrik> savings in what? time or bytecode size? constructed Fredrik> micro-benchmarks, or examples from real-life code? Fredrik> do we have any stat