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 dict and set literals instead of calls to dict() and set() #5559

Merged
merged 1 commit into from Nov 6, 2017
Merged

Use dict and set literals instead of calls to dict() and set() #5559

merged 1 commit into from Nov 6, 2017

Conversation

jdufresne
Copy link
Contributor

@jdufresne jdufresne commented Nov 4, 2017

Set literals are available on all supported Python versions. They are idiomatic and always faster:

$ python3 -m timeit '{}'
10000000 loops, best of 3: 0.0357 usec per loop
$ python3 -m timeit 'dict()'
10000000 loops, best of 3: 0.104 usec per loop
$ python3 -m timeit '{1, 2, 3}'
10000000 loops, best of 3: 0.0754 usec per loop
$ python3 -m timeit 'set([1, 2, 3])'
1000000 loops, best of 3: 0.228 usec per loop

Set literals are available on all supported Python versions. They are
idiomatic and always faster:

$ python3 -m timeit '{}'
10000000 loops, best of 3: 0.0357 usec per loop
$ python3 -m timeit 'dict()'
10000000 loops, best of 3: 0.104 usec per loop

$ python3 -m timeit '{1, 2, 3}'
10000000 loops, best of 3: 0.0754 usec per loop
$ python3 -m timeit 'set([1, 2, 3])'
1000000 loops, best of 3: 0.228 usec per loop
@xordoquy
Copy link
Collaborator

xordoquy commented Nov 6, 2017

How much does it impacts a full request ?

Copy link
Collaborator

@carltongibson carltongibson left a comment

OK. This looks good.

I think the speed issue is a non-issue really. For me it's more that this syntax will be idiomatic as time passes.

@carltongibson carltongibson added this to the 3.7.2 milestone Nov 6, 2017
@carltongibson carltongibson merged commit 0552810 into encode:master Nov 6, 2017
1 check passed
@jdufresne
Copy link
Contributor Author

jdufresne commented Nov 6, 2017

How much does it impacts a full request ?

Probably not much in practice. However, literals are always supported, always idiomatic, always readable, and always faster. Most of the time, they're always the preferred choice, even without benchmarks.

@jdufresne jdufresne deleted the literals branch Nov 9, 2017
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