mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Improve the memory performance and speed of heapq.nsmallest() by using
an alternate algorithm when the number of selected items is small relative to the full iterable.
This commit is contained in:
parent
2e6694086f
commit
b25aa36f83
2 changed files with 24 additions and 0 deletions
|
@ -92,6 +92,7 @@ class TestHeap(unittest.TestCase):
|
|||
def test_nsmallest(self):
|
||||
data = [random.randrange(2000) for i in range(1000)]
|
||||
self.assertEqual(nsmallest(data, 400), sorted(data)[:400])
|
||||
self.assertEqual(nsmallest(data, 50), sorted(data)[:50])
|
||||
|
||||
def test_largest(self):
|
||||
data = [random.randrange(2000) for i in range(1000)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue