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

Generalize benchmarks #532

Closed
wants to merge 25 commits into from
Closed

Conversation

Erotemic
Copy link
Contributor

In an effort to procrastinate on what I really need to be doing I did a rework of the existing benchmarks script, and I added a new one based on my timerit module (https://github.com/Erotemic/timerit/).

It's still a work in progress, because I do have to stop procrastinating, but here is a teaser plot that visually compares implementation performance on specific tasks over a range of sizes. Error bars included.

This branch is currently based on another PR, but I do plan to clean it up / factor out additional dependencies if that is desired.

To make the nice plots it will depend on seaborn and pandas. For timing, I do want to use timerit instead of timeit as it makes the benchmarks much easier to write. I could factor out ubelt, but it's small and I do find it useful.

The main dependency that could be excluded is openskill, which is used to generate overall probability estimates that one library is faster than another. (Although currently nujson is slightly beating ujson, but maybe that's just because my PR has a slowdown). Part of the point of this is to determine when a patch introduces a performance regression.

image

JustAnotherArchivist and others added 22 commits April 17, 2022 03:49
This allows surrogates anywhere in the input, compatible with the json module from the standard library.

This also refactors two interfaces:
- The `PyUnicode` to `char*` conversion is moved into its own function, separated from the `JSONTypeContext` handling, so it can be reused for other things in the future (e.g. indentation and separators) which don't have a type context.
- Converting the `char*` output to a Python string with surrogates intact requires the string length for `PyUnicode_Decode` & Co. While `strlen` could be used, the length is already known inside the encoder, so the encoder function now also takes an extra `size_t` pointer argument to return that and no longer NUL-terminates the string. This also permits output that contains NUL bytes (even though that would be invalid JSON), e.g. if an object's `__json__` method return value were to contain them.

Fixes ultrajson#156
Fixes ultrajson#447
Supersedes ultrajson#284
[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Fix compiler warnings

Update python/objToJSON.c

Co-authored-by: JustAnotherArchivist <JustAnotherArchivist@users.noreply.github.com>

camelCase

whitespace

Update tests/test_ujson.py

Co-authored-by: JustAnotherArchivist <JustAnotherArchivist@users.noreply.github.com>
@bwoodsend
Copy link
Collaborator

I don't see anything wrong with the benchmark picking up dependencies for graphics or for doing the timing (although it's intersting to see yet another timeit but not as awkward as timeit library floating around - I'll have to see if I like it more than sloth). Happy procrastinating!

@JustAnotherArchivist
Copy link
Collaborator

I like pretty graphs. :-)

Just so it isn't missed later, this PR currently includes commits from #518 and #530 and other functional changes which should be removed before this gets merged.

@Erotemic Erotemic mentioned this pull request May 26, 2022
3 tasks
@Erotemic
Copy link
Contributor Author

Closed in favor of #542

@Erotemic Erotemic closed this May 30, 2022
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

Successfully merging this pull request may close these issues.

None yet

3 participants