(-1)**1000

Ian Kelly ian.g.kelly at gmail.com
Wed Oct 22 16:29:13 CEST 2014


On Wed, Oct 22, 2014 at 4:43 AM, Tim Chase
<python.list at tim.thechases.com> wrote:
> On 2014-10-22 12:29, Peter Otten wrote:
>> That looks like log(a) while a parity check takes constant time:
>>
>> $ python3 -m timeit -s 'a = 10**10' 'a & 1'
>> 10000000 loops, best of 3: 0.124 usec per loop
>> $ python3 -m timeit -s 'a = 10**100' 'a & 1'
>> 10000000 loops, best of 3: 0.124 usec per loop
>> $ python3 -m timeit -s 'a = 10**1000' 'a & 1'
>> 10000000 loops, best of 3: 0.122 usec per loop
>
> Just for the record, this is a one-bit even/odd check

Which is just a verbose way of writing "parity check", even if that
phrase is usually used in another context.



More information about the Python-list mailing list