Would there be support for a more general cmp/__cmp__

Antoon Pardon apardon at forel.vub.ac.be
Fri Oct 28 05:17:52 EDT 2005


Op 2005-10-28, Antoon Pardon schreef <apardon at forel.vub.ac.be>:
> Op 2005-10-26, Ron Adam schreef <rrr at ronadam.com>:
>>
>
> These are the results.
>
><class '__main__.cla'>: 1000 repeats, 1000 long, 10.061425 secs
><class '__main__.clb'>: 1000 repeats, 1000 long,  9.544035 secs
><class '__main__.clc'>: 1000 repeats, 1000 long, 10.450864 secs
><class '__main__.cld'>: 1000 repeats, 1000 long, 15.566061 secs
><class '__main__.cle'>: 1000 repeats, 1000 long, 15.776443 secs
>
> Results on a longer sequence were:
>
><class '__main__.cla'>: 1000 repeats, 10000 long, 146.722443 secs
><class '__main__.clb'>: 1000 repeats, 10000 long, 139.480863 secs
><class '__main__.clc'>: 1000 repeats, 10000 long, 152.623424 secs
><class '__main__.cld'>: 1000 repeats, 10000 long, 224.630926 secs
><class '__main__.cle'>: 1000 repeats, 10000 long, 228.663825 secs
>
> The most interesting result of this test is the difference between
> cld and cle. IMO this difference is an indication of the cost
> that my idea would have on sorting, should it be implemented.
> That would be around 2%. I think that is bearable. Especially
> since this were very simple routines. The moment the comparison
> calculation become heavier, the relative contribution of the
> try: except will diminuish.
>
> If you are concerned about sorting times, I think you should
> be more concerned about Guido's idea of doing away with __cmp__.
> Sure __lt__ is faster. But in a number of cases writing __cmp__
> is of the same complexity as writing __lt__. So if you then
> need a __lt__, __le__, __eq__, __ne__, __gt__ and __ge__ it
> would be a lot easier to write a __cmp__ and have all rich
> comparisons methods call this instead of duplicating the code
> about six times. So you would be more or less forced to write
> your class as class cld or cle. This would have a bigger
> impact on sorting times than my suggestion.

And as an afterthought: Adding __slots__ increased the
sorting speed between 7.5 and 9.0%

-- 
Antoon Pardon



More information about the Python-list mailing list