Created
November 24, 2014 16:11
-
-
Save brunal/a7f6501675d87385a745 to your computer and use it in GitHub Desktop.
python random perf
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
from sys import argv | |
def fast(): | |
from numpy.random import uniform | |
return uniform(0.0, 1.0, 1000000) | |
def slow(): | |
from random import uniform | |
return [uniform(0.0, 1.0) for i in range(1000000)] | |
def print_deciles(variates): | |
variates.sort() | |
for i in range(0, 1000000, 100000): | |
print variates[i] | |
if __name__ == '__main__': | |
try: | |
source = {'fast': fast, | |
'slow': slow}[argv[1]] | |
except (KeyError, IndexError): | |
print "Pick option 'fast' or 'slow'" | |
else: | |
print_deciles(source()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment