List problem

Bengt Richter bokr at oz.net
Mon Nov 1 04:58:23 EST 2004


On Mon, 1 Nov 2004 09:46:09 +0200, aleaxit at yahoo.com (Alex Martelli) wrote:

>Bengt Richter <bokr at oz.net> wrote:
>   ...
>> >def delsome_am(n=1000000, todel=[2]):
>> >    a = range(n)
>> >    a = [x for x in a if x not in todel]
>>      ^-- shud be a[:] ;-)
>> (I think the missing return a is in the noise ;-)
>
>Right, sorry.
>
>> >kallisti:/tmp alex$ python -mtimeit -s'import br' 'br.delsome_br()'
>> >10 loops, best of 3: 4.44 sec per loop
>> >kallisti:/tmp alex$ python -mtimeit -s'import br' 'br.delsome_am()'
>> >10 loops, best of 3: 3.92 sec per loop
>> >
>> I thought you had 'way faster machines than mine. Neither time is an
>> improvement over delsome_br for 2.3.2 on my old box. I wonder what's up.
>
>I ran these on an 800 MHz laptop, the one I invariably use for netting
>-- best ergonomics.  OK, I'll try with faster machines when I get a
>chance -- I'm surprised you measure almost a 1:2 ratio with _br faster.
>
Maybe the listcomp optimizations were introduced in 2.3.4? Or even 2.4.x?

I have Python 2.3.2 on an old 300 MHz P2 with 320 MB RAM and NT4 as OS,
so the mystery deepens ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list