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

Use tuple literals instead of tuple class/constructor #247

Merged
merged 1 commit into from Dec 4, 2018

Conversation

@vstoykov
Copy link
Contributor

vstoykov commented Nov 6, 2018

This can be a micro optimization (blind guess I was not done any measurements) because tuple name will not be looked in the global scope and also there will not be extra function call.

@msiemens

This comment has been minimized.

Copy link
Owner

msiemens commented Dec 4, 2018

It's not a big difference, but I'll take it 🙃 Thanks for the contribution!

In [23]: %timeit QueryOld()['value']['val']
8.91 µs ± 23.5 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [22]: %timeit Query()['value']['val']
7.47 µs ± 21.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [25]: %timeit QueryOld().value < 1
8.83 µs ± 63.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

In [24]: %timeit Query().value < 1
7.69 µs ± 53.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
@msiemens msiemens merged commit 0fb4233 into msiemens:master Dec 4, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 100.0%
Details
@msiemens

This comment has been minimized.

Copy link
Owner

msiemens commented Dec 4, 2018

I'll try to get a release out that includes this change next week.

@eugene-eeo

This comment has been minimized.

Copy link
Contributor

eugene-eeo commented Dec 4, 2018

Side note: I think what I thought back then was that the attribute chaining (e.g. Query().a.b) should be fast and somehow I used a list instead. But you're right, this is much better since it avoids creating new lists and converting them into tuples. 😅

@vstoykov vstoykov deleted the vstoykov:tuple-literals branch Dec 5, 2018
@msiemens

This comment has been minimized.

Copy link
Owner

msiemens commented Dec 12, 2018

FYI, this is is now included in TinyDB v3.12.2 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.