Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created November 6, 2015 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/7f283bf8294c235cc1ea to your computer and use it in GitHub Desktop.
Save podhmo/7f283bf8294c235cc1ea to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
import timeit
N = 10000
result = timeit.timeit(
setup="""
import json
data = '''
{
"x": [1, 2, 3],
"y": "foo",
"z": {"a": "a", "b": "b"}
}
'''
""",
stmt="json.loads(data)",
number=N
)
result2 = timeit.timeit(
setup="""
from collections import OrderedDict
import json
data = '''
{
"x": [1, 2, 3],
"y": "foo",
"z": {"a": "a", "b": "b"}
}
'''
""",
stmt="json.loads(data, object_pairs_hook=OrderedDict)",
number=N
)
result3 = timeit.timeit(
setup="""
from collections import OrderedDict
import json
decoder = json.JSONDecoder(object_hook=None, object_pairs_hook=OrderedDict)
data = '''
{
"x": [1, 2, 3],
"y": "foo",
"z": {"a": "a", "b": "b"}
}
'''
""",
stmt="decoder.decode(data)",
number=N
)
print(result)
print(result2)
print(result3)
@podhmo
Copy link
Author

podhmo commented Nov 6, 2015

0.138908863068
0.591463088989
0.519216060638

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment