Skip to content

Instantly share code, notes, and snippets.

@brunal
Created November 24, 2014 16:11
Show Gist options
  • Save brunal/a7f6501675d87385a745 to your computer and use it in GitHub Desktop.
Save brunal/a7f6501675d87385a745 to your computer and use it in GitHub Desktop.
python random perf
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