Re: Performance of list vs. set equality operations

2010-04-10 Thread Terry Reedy
On 4/10/2010 8:32 AM, Stefan Behnel wrote: Steven D'Aprano, 08.04.2010 03:41: On Wed, 07 Apr 2010 10:55:10 -0700, Raymond Hettinger wrote: If the two collections have unequal sizes, then both ways immediately return unequal. Perhaps I'm misinterpreting what you are saying, but I can't conf

Re: Performance of list vs. set equality operations

2010-04-10 Thread Stefan Behnel
Steven D'Aprano, 08.04.2010 03:41: On Wed, 07 Apr 2010 10:55:10 -0700, Raymond Hettinger wrote: [Gustavo Nare] In other words: The more different elements two collections have, the faster it is to compare them as sets. And as a consequence, the more equivalent elements two collections have, th

Re: Performance of list vs. set equality operations

2010-04-09 Thread Raymond Hettinger
> > I don't know if it's a good "fix" anyway.  If you subclass an internal > > type, you can certainly supply your own rich comparison methods, which > > would (IMO) put the CPU computation burden where it belongs if you > > decide to do something goofy like subclass a list and then override > > __

Re: Performance of list vs. set equality operations

2010-04-09 Thread Patrick Maupin
On Apr 9, 1:07 pm, "Gabriel Genellina" wrote: > En Thu, 08 Apr 2010 21:02:23 -0300, Patrick Maupin   > escribió: > > > On Apr 8, 6:35 pm, "Gabriel Genellina" wrote: > > >> The CPython source contains lots of shortcuts like that. Perhaps the   > >> checks should be stricter in some cases, but I i

Re: Performance of list vs. set equality operations

2010-04-09 Thread Gabriel Genellina
En Thu, 08 Apr 2010 21:02:23 -0300, Patrick Maupin escribió: On Apr 8, 6:35 pm, "Gabriel Genellina" wrote: The CPython source contains lots of shortcuts like that. Perhaps the checks should be stricter in some cases, but I imagine it's not so easy to fix: lots of code was written in the p

Re: Performance of list vs. set equality operations

2010-04-08 Thread Patrick Maupin
On Apr 8, 6:35 pm, "Gabriel Genellina" wrote: > The CPython source contains lots of shortcuts like that. Perhaps the   > checks should be stricter in some cases, but I imagine it's not so easy to   > fix: lots of code was written in the pre-2.2 era, assuming that internal   > types were not subcl

Re: Performance of list vs. set equality operations

2010-04-08 Thread Gabriel Genellina
En Thu, 08 Apr 2010 04:07:53 -0300, Steven D'Aprano escribió: On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote: [Raymond Hettinger] > If the two collections have unequal sizes, then both ways immediately > return unequal. [Steven D'Aprano] Perhaps I'm misinterpreting what you

Re: Performance of list vs. set equality operations

2010-04-08 Thread Raymond Hettinger
[Steven D'Aprano] > So what happens in my example with a subclass that (falsely) reports a > different length even when the lists are the same? > > I can guess that perhaps Py_SIZE does not call the subclass __len__ > method, and therefore is not fooled by it lying. Is that the case? Yes. Py_SIZE

Re: Performance of list vs. set equality operations

2010-04-08 Thread Terry Reedy
On 4/8/2010 3:07 AM, Steven D'Aprano wrote: On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote: [Raymond Hettinger] If the two collections have unequal sizes, then both ways immediately return unequal. [Steven D'Aprano] Perhaps I'm misinterpreting what you are saying, but I can't c

Re: Performance of list vs. set equality operations

2010-04-08 Thread Steven D'Aprano
On Wed, 07 Apr 2010 20:14:23 -0700, Raymond Hettinger wrote: > [Raymond Hettinger] >> > If the two collections have unequal sizes, then both ways immediately >> > return unequal. > > [Steven D'Aprano] >> Perhaps I'm misinterpreting what you are saying, but I can't confirm >> that behaviour, at le

Re: Performance of list vs. set equality operations

2010-04-07 Thread Raymond Hettinger
[Raymond Hettinger] > > If the two collections have unequal sizes, then both ways immediately > > return unequal. [Steven D'Aprano] > Perhaps I'm misinterpreting what you are saying, but I can't confirm that > behaviour, at least not for subclasses of list: For doubters, see list_richcompare() in

Re: Performance of list vs. set equality operations

2010-04-07 Thread Patrick Maupin
On Apr 7, 8:41 pm, Steven D'Aprano wrote: > On Wed, 07 Apr 2010 10:55:10 -0700, Raymond Hettinger wrote: > > [Gustavo Nare] > >> In other words: The more different elements two collections have, the > >> faster it is to compare them as sets. And as a consequence, the more > >> equivalent elements

Re: Performance of list vs. set equality operations

2010-04-07 Thread Steven D'Aprano
On Wed, 07 Apr 2010 10:55:10 -0700, Raymond Hettinger wrote: > [Gustavo Nare] >> In other words: The more different elements two collections have, the >> faster it is to compare them as sets. And as a consequence, the more >> equivalent elements two collections have, the faster it is to compare >>

Re: Performance of list vs. set equality operations

2010-04-07 Thread Raymond Hettinger
[Gustavo Nare] > In other words: The more different elements two collections have, the > faster it is to compare them as sets. And as a consequence, the more > equivalent elements two collections have, the faster it is to compare > them as lists. > > Is this correct? If two collections are equal,

Re: Performance of list vs. set equality operations

2010-04-06 Thread Lie Ryan
On 04/07/10 04:11, Gustavo Narea wrote: > Hello! > > Could you please confirm whether my understanding of equality > operations in sets and lists is correct? This is how I think things > work, partially based on experimentation and the online documentation > for Python: > > When you compare two l

Re: Performance of list vs. set equality operations

2010-04-06 Thread Jack Diederich
On Tue, Apr 6, 2010 at 2:11 PM, Gustavo Narea wrote: > Hello! > > Could you please confirm whether my understanding of equality > operations in sets and lists is correct? This is how I think things > work, partially based on experimentation and the online documentation > for Python: > > When you c

Re: Performance of list vs. set equality operations

2010-04-06 Thread Chris Colbert
:slaps forehead: good catch. On Tue, Apr 6, 2010 at 5:18 PM, Gustavo Narea wrote: > On Apr 6, 7:28 pm, Chris Colbert wrote: >> the proof is in the pudding: >> >> In [1]: a = range(1) >> >> In [2]: s = set(a) >> >> In [3]: s2 = set(a) >> >> In [5]: b = range(1) >> >> In [6]: a == b >> Ou

Re: Performance of list vs. set equality operations

2010-04-06 Thread Gustavo Narea
On Apr 6, 7:28 pm, Chris Colbert wrote: > the proof is in the pudding: > > In [1]: a = range(1) > > In [2]: s = set(a) > > In [3]: s2 = set(a) > > In [5]: b = range(1) > > In [6]: a == b > Out[6]: True > > In [7]: s == s2 > Out[7]: True > > In [8]: %timeit a == b > 1000 loops, best of 3: 2

Re: Performance of list vs. set equality operations

2010-04-06 Thread Chris Colbert
the proof is in the pudding: In [1]: a = range(1) In [2]: s = set(a) In [3]: s2 = set(a) In [5]: b = range(1) In [6]: a == b Out[6]: True In [7]: s == s2 Out[7]: True In [8]: %timeit a == b 1000 loops, best of 3: 204 us per loop In [9]: %timeit s == s2 1 loops, best of 3: 124 us