Sorting: too different times. Why?
clp2 at rebertia.com
Sun Nov 22 12:07:08 CET 2009
On Sun, Nov 22, 2009 at 2:56 AM, n00m <n00m at narod.ru> wrote:
> I was expecting the 1st method would be *slower* than the 2nd one :-)
> Or at least equal... Just random ("intuitive") expectations
The second method repeatedly looks up left_item.__class__.__cmp__
(i.e. Vector.__cmp__) when doing the necessary comparisons between the
list items; while these lookups are optimized and are fast, they are
not free and cannot be skipped because Python doesn't know the list
contains only Vectors.
The first method uses the single provided comparison function and thus
does no such lookups; hence, it's faster.
That's my guess anyway.
More information about the Python-list