5 Dec
2017
5 Dec
'17
4:12 a.m.
On Mon, 4 Dec 2017 19:37:02 +0000
Barry Scott
I wondered what the performance would be and tested the following code:
[...]
it outputs this for my with python 3.6.0
10000 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. Regards Antoine.