homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author loewis
Recipients dschult, loewis, rhettinger
Date 2009年04月09日.22:27:20
SpamBayes Score 1.498135e-12
Marked as misclassified No
Message-id <49DE7646.7040501@v.loewis.de>
In-reply-to <1239312199.25.0.914608525949.issue5730@psf.upfronthosting.co.za>
Content
> Martin, any thoughts?
The same as always: Dan, do you have any benchmarks
that demonstrate the speedup?
Looking at the usage of setdefault in the standard library,
it seems that it's most of the time either an interned string,
or an object hashed by memory address that gets passed as a
key. Hashing these is very cheap, so I would be skeptical
that any real benefits can be demonstrated.
I also agree with Raymond that, by nature, setdefault only
calls hash() twice on the very first call, and not in subsequent
calls, so even if there was an improvement, it shouldn't matter
for the total runtime. I also agree that setdefault is somewhat
inappropriate for performance critical code, since it will create
the default value anyway (often a dict or a list), even if a
value is already stored. So users who care about performance
should write something like
try:
 l = d[k]
except KeyError:
 l = d[k] = []
to avoid the list creation in the common case, or use a
defaultdict in the first place.
History
Date User Action Args
2009年04月09日 22:27:22loewissetrecipients: + loewis, rhettinger, dschult
2009年04月09日 22:27:20loewislinkissue5730 messages
2009年04月09日 22:27:20loewiscreate

AltStyle によって変換されたページ (->オリジナル) /