Skip to content

Conversation

jdufresne
Copy link
Contributor

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
Contributor

xordoquy commented Nov 6, 2017

How much does it impacts a full request ?

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@jdufresne
Copy link
Contributor Author

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 November 9, 2017 04:09
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.

3 participants