Re: dict.get and str.xsplit

2008-02-26 Thread Gabriel Genellina
En Tue, 26 Feb 2008 12:33:01 -0200, <[EMAIL PROTECTED]> escribió: > On Feb 26, 8:14 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> 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

Re: dict.get and str.xsplit

2008-02-26 Thread marek . rocki
[EMAIL PROTECTED] napisał(a): > [EMAIL PROTECTED]: > > As for the original prooblem, why not use > > defaultdict? I think it's the most idiomatic way to achieve what we > > want. And also the fastest one, according to my quick-and-dirty tests: > > It adds the new keys, I can't accept that: Right,

Re: dict.get and str.xsplit

2008-02-26 Thread bearophileHUGS
[EMAIL PROTECTED]: > As for the original prooblem, why not use > defaultdict? I think it's the most idiomatic way to achieve what we > want. And also the fastest one, according to my quick-and-dirty tests: It adds the new keys, I can't accept that: >>> from collections import defaultdict as dd >>

Re: dict.get and str.xsplit

2008-02-26 Thread marek . rocki
[EMAIL PROTECTED] napisał(a): > It's slower still, despite doing the lookup two times half of the > times (half keys are present in the test set). The "in" is an > operator, it's faster than a method call, but I don't understand the > other details. Now the difference between 1.78 and 1.56 is small

Re: dict.get and str.xsplit

2008-02-26 Thread castironpi
On Feb 26, 8:40 am, [EMAIL PROTECTED] wrote: > Marc 'BlackJack' Rintsch: > > > I guess it's the method lookup that's the slow part.  Factor it out of the > > loop and measure again:: > > I did know of that optimization, but sometimes I "forget" about it... > The new timings: > > Output timings, bes

Re: dict.get and str.xsplit

2008-02-26 Thread bearophileHUGS
Marc 'BlackJack' Rintsch: > I guess it's the method lookup that's the slow part. Factor it out of the > loop and measure again:: I did know of that optimization, but sometimes I "forget" about it... The new timings: Output timings, best of 3, unloaded CPU: 2.32 s with adict.get 1.56 s with "in"

Re: dict.get and str.xsplit

2008-02-26 Thread Marc 'BlackJack' Rintsch
On Tue, 26 Feb 2008 06:33:01 -0800, castironpi wrote: > On Feb 26, 8:14 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> 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

Re: dict.get and str.xsplit

2008-02-26 Thread castironpi
On Feb 26, 8:14 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> 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 semantica

Re: dict.get and str.xsplit

2008-02-26 Thread Steve Holden
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 di

Re: dict.get and str.xsplit

2008-02-26 Thread Marc 'BlackJack' Rintsch
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,

dict.get and str.xsplit

2008-02-26 Thread bearophileHUGS
When I use dictionaries I find the dict.get() method very handy, and I'd like to use it often, but I think it's quite slow. This is a small benchmark: from random import randrange from timeit import default_timer as clock def main(N, M): keys = list(set(randrange(2*N) for n in xrange(N)))