Skip to content

Instantly share code, notes, and snippets.

@j2labs
Created April 14, 2011 18:02
Show Gist options
  • Select an option

  • Save j2labs/920078 to your computer and use it in GitHub Desktop.

Select an option

Save j2labs/920078 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python -u
# Using Python 2.6
# Starting json... done: 17.8986079693
# Starting simplejson... done: 6.75326800346
# Starting cjson... done: 2.19219493866
# Starting ujson... done: 0.742480039597
# Starting pickle... done: 43.2633650303
# Starting cPickle... done: 6.45727396011
# Starting marshal... done: 1.2130010128
# Using Python 2.7
# Starting json... done: 5.84877085686
# Starting simplejson... done: 6.65995502472
# Starting cjson... done: 2.17661309242
# Starting ujson... done: 0.743311882019
# Starting pickle... done: 41.4778251648
# Starting cPickle... done: 7.08554387093
# Starting marshal... done: 1.19155406952
import time
import simplejson
import json
import cjson
import ujson
import pickle
import cPickle
import marshal
cjson.dumps = cjson.encode
cjson.loads = cjson.decode
small_and_simple = {
'foo': 'bar',
'food': 'barf',
'good': 'bars',
'dood': 'wheres your car?',
'wheres your car': 'dude?',
}
mods = [json, simplejson, cjson, ujson, pickle, cPickle, marshal]
for mod in mods:
print 'Starting %s... ' % (mod.__name__),
start = time.time()
for i in xrange(1000000):
mod.dumps(small_and_simple)
print 'done:', time.time() - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment