Created
April 3, 2011 03:01
-
-
Save rfk/900138 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import os | |
import cPickle as pickle | |
import cjson | |
import ujson | |
import tnetstring | |
cjson.dumps = cjson.encode | |
cjson.loads = cjson.decode | |
d = { | |
'foo': 'bar', | |
'food': 'barf', | |
'good': 'bars', | |
'dood': 'wheres your car?', | |
'wheres your car': 'dude?', | |
} | |
for _ in xrange(100): | |
d[os.urandom(20).encode("hex")] = os.urandom(20).encode("hex") | |
def test_mod(mod, iters=1000000): | |
print 'Starting %s...' % mod.__name__ | |
start = time.time() | |
for i in xrange(iters): | |
s = mod.dumps(d) | |
write = time.time() - start | |
start = time.time() | |
for i in xrange(iters): | |
dl = mod.loads(s) | |
read = time.time() - start | |
print 'Read: %f, Write: %f, Total %f' % (read, write, read + write) | |
to_test = [tnetstring, cjson, ujson, pickle] | |
for mod in to_test: | |
test_mod(mod) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment