Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27808

Re: Filter versus comprehension (was Re: something about split()???)

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Filter versus comprehension (was Re: something about split()???)
Date 2012-08-24 12:04 -0400
References (5 earlier) <CADYZVBCZZ3cAHGDe=wyi62Hg9+qU_r2U8F+85gHEOzs0Ekv1BA@mail.gmail.com> <k11ro8$cer$1@ger.gmane.org> <k121ob$lp9$1@ger.gmane.org> <mailman.3665.1345653816.4697.python-list@python.org> <960e4798-745b-4e9b-aedb-14aae986d086@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.3759.1345824330.4697.python-list@python.org> (permalink)

Show all headers | View raw


On 8/24/2012 10:44 AM, Ramchandra Apte wrote:
> On Wednesday, 22 August 2012 22:13:04 UTC+5:30, Terry Reedy  wrote:

>>   >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(0)")
 >>
>> 0.91
>>
>>   >>> timeit.timeit("list(i for i in ranger if False)", "ranger=range(20)")
>>
>> 1.28
>>
>>   >>> timeit.timeit("list(filter(lambda i: False, ranger))",
>>
>> "ranger=range(0)")
>>
>> 0.83
>>
>>   >>> timeit.timeit("list(filter(lambda i: False, ranger))",
>>
>> "ranger=range(20)")
>>
>> 2.60

Your mail agent in inserting blank lines in quotes -- google?
See if you can turn that off.

> Your examples with lambda i:False are unrealistic - you are comparing
 > `if False` vs <lambda function>(xx) - function call vs boolean check

That is exactly the comparison I wanted to make. The iteration + boolean 
check takes .37 for 20 items, the iteration + call 1.77.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Filter versus comprehension (was Re: something about split()???) Terry Reedy <tjreedy@udel.edu> - 2012-08-22 12:43 -0400
  Re: Filter versus comprehension (was Re: something about split()???) Ramchandra Apte <maniandram01@gmail.com> - 2012-08-24 07:44 -0700
    Re: Filter versus comprehension (was Re: something about split()???) Terry Reedy <tjreedy@udel.edu> - 2012-08-24 12:04 -0400
    Re: Filter versus comprehension (was Re: something about split()???) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-24 14:29 -0400
      Re: Filter versus comprehension (was Re: something about split()???) Walter Hurry <walterhurry@lavabit.com> - 2012-08-24 19:03 +0000
        Re: Filter versus comprehension (was Re: something about split()???) Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-08-24 17:56 -0400
          Re: Filter versus comprehension (was Re: something about split()???) Walter Hurry <walterhurry@lavabit.com> - 2012-08-24 22:55 +0000
        Re: Filter versus comprehension (was Re: something about split()???) Terry Reedy <tjreedy@udel.edu> - 2012-08-24 18:03 -0400
        Re: Filter versus comprehension (was Re: something about split()???) Emile van Sebille <emile@fenx.com> - 2012-08-24 15:15 -0700
        Re: Filter versus comprehension (was Re: something about split()???) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-24 23:28 +0100
        Re: Filter versus comprehension (was Re: something about split()???) Ned Deily <nad@acm.org> - 2012-08-24 15:36 -0700
        Re: Filter versus comprehension (was Re: something about split()???) Ned Deily <nad@acm.org> - 2012-08-24 15:39 -0700
        Re: Filter versus comprehension (was Re: something about split()???) David Robinow <drobinow@gmail.com> - 2012-08-25 08:57 -0400
        Re: Filter versus comprehension (was Re: something about split()???) Tim Golden <mail@timgolden.me.uk> - 2012-08-25 16:31 +0100
  Re: Filter versus comprehension (was Re: something about split()???) Ramchandra Apte <maniandram01@gmail.com> - 2012-08-24 07:44 -0700

csiph-web