Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'python3': 0.07; 'cc:addr :python-list': 0.11; '-tkc': 0.16; '10000000': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'record,': 0.16; 'to:addr:web.de': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'adds': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; '(which': 0.31; 'constant': 0.31; 'time:': 0.31; 'useful': 0.36; 'charset:us- ascii': 0.36; 'received:10': 0.37; 'counts': 0.83; 'otten': 0.84; 'parity': 0.84; 'received:108': 0.93 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1413974407781:1953130564 X-MC-Ingress-Time: 1413974407448 Date: Wed, 22 Oct 2014 05:43:02 -0500 From: Tim Chase To: Peter Otten <__peter__@web.de> Subject: Re: (-1)**1000 In-Reply-To: References: <54476a77$0$21664$426a74cc@news.free.fr> <5447786d$0$12750$426a74cc@news.free.fr> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413975559 news.xs4all.nl 2976 [2001:888:2000:d::a6]:43966 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:79430 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 useful & fast in this sign-of-large-exponent case), not a parity check (which typically counts the number of "1" bits, adds the parity bit, and asserts the result is even) -tkc