dict.get and str.xsplit
Steve Holden
steve at holdenweb.com
Tue Feb 26 09:34:02 EST 2008
Marc 'BlackJack' Rintsch wrote:
> On Tue, 26 Feb 2008 06:02:12 -0800, bearophileHUGS wrote:
>
>> This is a real difference, that has real impact on the programs I
>> write, so I often use the if/else approach, despite the dict.get()
>> method being semantically fitter and shorter.
>> So can the dict.get() method be speed up? And if not, why?
>
> I guess it's the method lookup that's the slow part. Factor it out of the
> loop and measure again::
>
> adict_get = adict.get
> for _ in xrange(M):
> for k in keys1:
> r = adict_get(k, None)
> for k in keys2:
> r = adict_get(k, None)
And think about using the timeit module, since it's been included among
the batteries for your convenience, and it removes some common pitfalls
with cross-platform timings.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list