Skip to content

Instantly share code, notes, and snippets.

@her0e1c1
her0e1c1 / gist:899e22e777be6b91c46c9ec102bb087e
Created April 8, 2016 09:37
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]$
@her0e1c1
her0e1c1 / grep.py
Last active January 16, 2016 02:49
grep
# print common area of sorted [(a_i, b_i)]
a = [1, 4, 5, 9]
b = [3, 6, 7, 9]
lines = "0 1 2 3 4 5 6 7 8 9 10".split()
def f(i, no):
if i == len(a):
return
if a[i] > no: