Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UUID Byte Benchmark Test for Cpython
import uuid
import time
import sys
from binascii import unhexlify
N = int(sys.argv[1])
class UpdatedUUID(uuid.UUID):
@property
def bytes(self):
return unhexlify(self.hex)
def run_test():
original_times = 0
updated_times = 0
for x in xrange(N):
original_uuid = uuid.uuid4()
updated_uuid = UpdatedUUID(hex=original_uuid.hex)
compare_uuids(original_uuid, updated_uuid)
original_times += benchmark(original_uuid)
updated_times += benchmark(updated_uuid)
print "Original Average: %s" % format_time(original_times)
print "Updated Average: %s" % format_time(updated_times)
def format_time(runtime):
return ('%.3f microseconds' % (runtime * 1000000.0 / N))
def benchmark(uuid_object):
t = time.time()
uuid_object.bytes
return time.time() - t
def compare_uuids(original, updated):
if original.bytes != updated.bytes:
print "Original UUID does not match updated UUID byte representation."
sys.exit(1)
run_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.