Tim Peters <t...@python.org> added the comment:

The attached tupsort.py gives a simple. focused example. Typical output on my 
box:

float       3.10
(float,)   11.75
[float]    25.68

It's sorting a large list of floats. In the first line the list contains plain 
floats. In the second line, each float was wrapped in a 1-tuple. In the last 
line, wrapped in a singleton list.

Essentially any overhead of any kind is more expensive than merely comparing 
two floats in HW, so overhead is approximately everything here.  The tuple and 
list comparison functions are very similar, and the large advantage of 
"(float,)" over "[float]" is mostly due to that unsafe_tuple_compare() uses one 
less PyObject_RichCompareBool() call to resolve each compare (assuming that all 
floats in the list are distinct, which I didn't check, but is almost certainly 
the case).

Getting rid of its other PyObject_RichCompareBool() should yield another nice 
speed boost.

The pattern is worth addressing because tuples are routinely used as key= 
arguments to achieve multi-key sorting.

----------
Added file: https://bugs.python.org/file50372/tupsort.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45530>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to