[Python-Dev] Python-Dev Digest, Vol 112, Issue 23

Peter Harris pete.alex.harris at gmail.com
Wed Nov 14 12:00:46 CET 2012


Chris Withers wrote:

> On 14/11/2012 09:58, Merlijn van Deen wrote:
> > On 14 November 2012 10:12, Chris Withers <chris at simplistix.co.uk> wrote:
> >> ...which made me a little sad
> >
> > Why did it make you sad? dict() takes 0.2?s, {} takes 0.04?s. In other
> > words: you can run dict() _five million_ times per second, and {}
> > twenty-five million times per second. That is 'a lot' and 'a lot'. It
> > also means you are unlikely to notice the difference in real-world
> > code. Just use the one you feel is clearer in the situation, and don't
> > worry about micro-optimalization.
>
> I'm inclined to agree, but it makes me sad for two reasons:
>
> - it's something that people get hung up on, for better or worse. (if it
> wasn't, Doug wouldn't have written his article)
>
> - it can make a difference, for example setting up a dict with many keys
> at the core of a type loop.
>
> Without looking at implementation, they should logically perform the
> same...
>
> Well, without looking at the implementation, you could form any opinion you
like about how they should perform. Still you could speculate that dict()
will
require a builtins name lookup, and that the process of passing keyword
arguments
might itself involve constructing a dictionary, so must inherently take at
least
a little longer than compiling a {} literal.

Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20121114/e458572c/attachment.html>


More information about the Python-Dev mailing list