Nov.
16

Chula comes with a guid generator class who's implementation is a bit naive.  Considering Python already has (probably much better) functionality builtin, I figured I'd see how fast they are.

Here's the way I tested them:

# Python imports
from random import randrange
from uuid import uuid1, uuid4
import time

# Chula imports
from chula.guid import guid

count = 10000

def timeit(fcn):
    def wrapper():
        start = time.time()
        fcn()
        print('%s %fs' % (fcn.__name__.ljust(20), time.time() - start))

    return wrapper

@timeit
def builtin_randrange():
    for i in xrange(count):
        x = randrange(100000000000000000000)

@timeit
def builtin_uuid1():
    for i in xrange(count):
        x = uuid1().hex

@timeit
def builtin_uuid4():
    for i in xrange(count):
        x = uuid4().hex

@timeit
def chula_guid():
    for i in xrange(count):
        x = guid()

if __name__ == '__main__':
    builtin_randrange()
    builtin_randrange()
    builtin_uuid1()
    builtin_uuid1()
    builtin_uuid4()
    builtin_uuid4()
    chula_guid()
    chula_guid()

Here are the results:

jmcfarlane@monster:~/Desktop$ python test.py 
builtin_randrange    0.053161s
builtin_randrange    0.053091s
builtin_uuid1        0.495005s
builtin_uuid1        0.487182s
builtin_uuid4        0.382016s
builtin_uuid4        0.380982s
chula_guid           1.156092s
chula_guid           1.154981s

To finish things off... this one really surprised me:

jmcfarlane@monster:~$ time for i in $(seq 10000); do uuidgen > /dev/null; done
real	0m22.086s
user	0m0.560s
sys	0m4.750s

So the moral of the story, is that Chula's guid generation isn't particularly fast, but shelling out to uuidgen is somehow even slower.



You can leave a (moderated) comment here:

Name:

Email address:

URL:

Comment:




Enter text above:

1

Total records: 1
FCGI/WSGI
0.13.3
146.435976 ms