Skip to content

Instantly share code, notes, and snippets.

@her0e1c1
Created April 8, 2016 09:37
Show Gist options
  • Save her0e1c1/899e22e777be6b91c46c9ec102bb087e to your computer and use it in GitHub Desktop.
Save her0e1c1/899e22e777be6b91c46c9ec102bb087e to your computer and use it in GitHub Desktop.
which is faster? random(string) or uuid4
[vagrant@debian-jessie]$ python -m timeit 'import string; import random; "".join([random.choice(string.digits) for _ in range(36)])'
100000 loops, best of 3: 15.3 usec per loop
python -m timeit 6.38s user 0.00s system 99% cpu 6.408 total
[vagrant@debian-jessie]$ python -m timeit 'import uuid; str(uuid.uuid4())'
100000 loops, best of 3: 18.2 usec per loop
python -m timeit 'import uuid; str(uuid.uuid4())' 6.13s user 1.54s system 98% cpu 7.763 total
[vagrant@debian-jessie]$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment