[Python-ideas] a sorting protocol dunder method?
solipsis at pitrou.net
Mon Dec 4 15:12:03 EST 2017
On Mon, 4 Dec 2017 19:37:02 +0000
Barry Scott <barry at barrys-emacs.org> wrote:
> I wondered what the performance would be and tested the following code:
> it outputs this for my with python 3.6.0
> key 0.010628s 10000 calls
> lt 0.053690s 119886 calls
> It seems that providing a key is ~5 times faster the depending on __lt__.
> (I even used a short circuit to se if __lt__ could beat key).
Thanks for taking the time to write a benchmark. I'm not surprised
by the results (and your __lt__ method isn't even complicated: the gap
could be very much wider). There is more to Python performance than
aggregate big-O algorithmic complexity.
More information about the Python-ideas