Skip to content

Instantly share code, notes, and snippets.

@draganHR
Last active August 29, 2015 14:00
Show Gist options
  • Save draganHR/11288392 to your computer and use it in GitHub Desktop.
Save draganHR/11288392 to your computer and use it in GitHub Desktop.
import json
import simplejson
import timeit
data = {
"firstName": "John",
"lastName": "Smith",
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": 10021
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
json_data = json.dumps(data, indent=4)
def test(name, lib):
print ("%s (%s):" % (name, lib.__version__))
print (" loads: %s" % timeit.timeit(lambda: lib.loads(json_data), number=10000))
print (" dumps: %s" % timeit.timeit(lambda: lib.dumps(data), number=10000))
test('json', json)
test('simplejson', simplejson)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment