Last active
August 29, 2015 14:10
-
-
Save rectalogic/ed28826ec4ec0798e411 to your computer and use it in GitHub Desktop.
limit sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[aw@jello tmp] $ python sort-slice.py | |
45920256 | |
[aw@jello tmp] $ python sort-heapq.py | |
5808128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resource | |
from random import random | |
from heapq import nlargest | |
nlargest(5, (random() for i in xrange(1000000))) | |
print resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import resource | |
from random import random | |
sorted((random() for i in xrange(1000000)), reverse=True)[:5] | |
print resource.getrusage(resource.RUSAGE_SELF).ru_maxrss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment