Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Bitshifts and "And" vs Floor-division and Modular Date: Fri, 7 Sep 2012 14:19:07 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 20 Message-ID: References: <50495556$0$29981$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader1.panix.com 1347027547 9249 64.122.56.22 (7 Sep 2012 14:19:07 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 7 Sep 2012 14:19:07 +0000 (UTC) User-Agent: slrn/pre1.0.0-18 (Linux) X-Received-Bytes: 1854 Xref: csiph.com comp.lang.python:28688 On 2012-09-07, Steven D'Aprano wrote: > My *guess* is that you mean *bitwise* operators, compared to numeric > operators like * and // (integer division). The runtime cost is mostly > dominated by the object-oriented overhead -- Python is not C or assembly, > and the integers are rich objects, not low-level bitfields, so the > difference between division and bitshifting is much less than you might > expect from assembly language. I don't suppose there's much of a chance that the OP is running Python on a CPU that doesn't have an integer divide instruction? If that _were_ the case, the difference would be more noticable, but would still probably not worth worrying about unless a truely huge number of operations were being done in a very tight loop with no intervening I/O operations. -- Grant Edwards grant.b.edwards Yow! I have accepted at Provolone into my life! gmail.com