Skip to content

Instantly share code, notes, and snippets.

@adl32x
Created October 31, 2015 12:49
Show Gist options
  • Save adl32x/e4c25b1751e373f4d8bb to your computer and use it in GitHub Desktop.
Save adl32x/e4c25b1751e373f4d8bb to your computer and use it in GitHub Desktop.
import random
a = range(1, 100)
def r1():
return random.choice(a)
def r2():
return a[random.randint(0, len(a)-1)]
"""
Save as test.py and:
$ python -mtimeit -n 10000 -s 'import test' 'test.r1()'
10000 loops, best of 3: 0.921 usec per loop
$ python -mtimeit -n 10000 -s 'import test' 'test.r2()'
10000 loops, best of 3: 2.59 usec per loop
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment