Message217859
Consolidate the logic for nlargest() into a single function. Remove both the C and pure Python base underlying code.
With all the logic in a single function, it only becomes necessary to create, store, and compare the data tuples when a need item is added to the heap. This means that the rest of the comparisons (checking to see whether a new item needs to be added to the heap) can run faster and not need to create a (key, order, elem) tuple.
The change reduces the number of tuples created and the number of ordering integers created.
When rich comparisons were introduced, tuple ordering comparisons became twice as expensive (they are compared elementwise for equality and then there is an additional comparison call to order the first differing element). Under the existing nlargest() code, we pay that price for every lement in the iterable. In the new code, we pay that price only for the small subset of the iterable that actually gets added to the heap.
After this, another patch for simplifying nsmallest() is forthcoming. |
|
Date |
User |
Action |
Args |
2014-05-04 05:57:10 | rhettinger | set | recipients:
+ rhettinger |
2014-05-04 05:57:09 | rhettinger | set | messageid: <1399183029.85.0.254812547035.issue21424@psf.upfronthosting.co.za> |
2014-05-04 05:57:09 | rhettinger | link | issue21424 messages |
2014-05-04 05:57:09 | rhettinger | create | |
|