Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance when deserializing a deeply nested object #320

Open
Midnighter opened this issue Nov 17, 2018 · 1 comment
Open

Performance when deserializing a deeply nested object #320

Midnighter opened this issue Nov 17, 2018 · 1 comment

Comments

@Midnighter
Copy link

I am dealing with large (1-3 MB), deeply nested structures that I'm communicating across web services. So I wanted to check if anything can be gained by using ujson. I ran the below code in CPython 3.6 with this object (result.json.gz) and was a bit surprised to find ujson being slower. The code is from an IPython session.

import json
import ujson


with open("result.json") as f:
    content = f.read()

%timeit json.loads(content)
4.28 ms ± 86.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

%timeit ujson.loads(content)
6.09 ms ± 116 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
@JustAnotherArchivist
Copy link
Collaborator

JustAnotherArchivist commented Jul 2, 2022

I just tested this with current versions (CPython 3.10.1 and ujson 5.4.0). On my machine, the two have virtually identical timings. So it's better now but still not great since ujson should really beat json easily...

$ python3 -m timeit -s 'import ujson as json'$'\n''with open("result.json") as f:'$'\n'' content = f.read()' 'json.loads(content)'
50 loops, best of 5: 5.86 msec per loop
$ python3 -m timeit -s 'import json'$'\n''with open("result.json") as f:'$'\n'' content = f.read()' 'json.loads(content)'
50 loops, best of 5: 5.91 msec per loop

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants