Created
November 6, 2015 16:36
-
-
Save podhmo/7f283bf8294c235cc1ea 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
# -*- 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
0.138908863068
0.591463088989
0.519216060638