Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28663
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <d@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'algorithm': 0.03; 'binary': 0.05; 'raises': 0.07; 'works.': 0.07; 'augmented': 0.09; 'compiler.': 0.09; 'longs': 0.09; 'meaningful': 0.09; 'cc:addr :python-list': 0.10; 'assignment.': 0.16; 'digits.': 0.16; 'wrote:': 0.17; 'code.': 0.20; 'bit': 0.21; 'assuming': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'setting': 0.26; 'bugs': 0.27; 'run': 0.28; 'accidentally': 0.29; 'question:': 0.29; 'maybe': 0.29; 'thursday,': 0.30; 'message.': 0.33; 'operations': 0.33; 'faster': 0.35; 'doing': 0.35; 'pm,': 0.35; 'similar': 0.35; 'but': 0.36; 'subject:" ': 0.36; 'should': 0.36; 'bad': 0.37; 'ok,': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'subject:-': 0.40; 'think': 0.40; "you'll": 0.62; 'time,': 0.62; 'more': 0.63; 'decided': 0.65; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'power': 0.74; 'clearer': 0.84; 'probable': 0.84; 'subject:Floor': 0.84; 'hundred': 0.95 |
| Date | Thu, 06 Sep 2012 21:46:12 -0400 |
| From | Dave Angel <d@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 |
| MIME-Version | 1.0 |
| To | jimbo1qaz <jimmyli1528@gmail.com> |
| Subject | Re: Bitshifts and "And" vs Floor-division and Modular |
| References | <d8d77115-dcb2-4769-a592-5fca0fc264bc@googlegroups.com> <df72ea70-4ae8-45e1-9743-64770170b901@googlegroups.com> |
| In-Reply-To | <df72ea70-4ae8-45e1-9743-64770170b901@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:zVC9J+GSIwFUMBQnZzQca04coptu7ptSVfSMr4Ssi6J NANJIpi+E4676hCr4DR9oRWPzhYkprlsndbv8D0GsE3BTWl1NT 1J+ZpPzx5Hy/drHYL/hOfJZIPw/Fy0+W5P6ZvLcsX0htF1RSt2 2Uce4c8xCxzXPtzhBs7WsiGDWhcU0J7UTu8BvpcaMtk9AUjMvA BqjiqmK1E90yJqIB2K4UqARhUudyPJvAxPN/wJfBDbq9FzNh6M CIazdLGwh0uw2u873QMEtu+74SJM4UK3o6v7m9zpDxL24YioNg NviaTYtV2XuuVvF/nF9Db1uY0yI1JBy77EQOLBrig+HpJUsDg= = |
| Cc | python-list@python.org |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | d@davea.name |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.344.1346982399.27098.python-list@python.org> (permalink) |
| Lines | 18 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346982399 news.xs4all.nl 6901 [2001:888:2000:d::a6]:47438 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28663 |
Show key headers only | View raw
On 09/06/2012 09:30 PM, jimbo1qaz wrote: > On Thursday, September 6, 2012 5:01:12 PM UTC-7, jimbo1qaz wrote: >> Is it faster to use bitshifts or floor division? And which is better, & or %? >> >> All divisors and mods are power of 2, so are binary operations faster? And are they considered bad style? > OK, I decided to change my code. Which raises a similar question: Which one is better for setting a bit of a byte: |= or +=, assuming each will only be run once? Intuitively, I think |=, but some timeits are inconclusive, mainly because I don't know how it works. Maybe i should have been clearer in my message. i don't think you'll find a meaningful difference unless you're doing longs of a few hundred digits. So if the algorithm is to OR on a bit, please use a |= augmented assignment. not only will it ward off probable bugs when you accidentally try to set the bit a second time, but it reads better for the reader of the program. The reader is more important than the compiler. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Bitshifts and "And" vs Floor-division and Modular jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-06 17:01 -0700
Re: Bitshifts and "And" vs Floor-division and Modular Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-07 01:30 +0100
Re: Bitshifts and "And" vs Floor-division and Modular jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-06 18:05 -0700
Re: Bitshifts and "And" vs Floor-division and Modular jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-06 18:05 -0700
Re: Bitshifts and "And" vs Floor-division and Modular jimbo1qaz <jimmyli1528@gmail.com> - 2012-09-06 18:30 -0700
Re: Bitshifts and "And" vs Floor-division and Modular Dave Angel <d@davea.name> - 2012-09-06 21:46 -0400
Re: Bitshifts and "And" vs Floor-division and Modular Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-07 02:23 +0000
Re: Bitshifts and "And" vs Floor-division and Modular Dave Angel <d@davea.name> - 2012-09-06 21:36 -0400
Re: Bitshifts and "And" vs Floor-division and Modular Terry Reedy <tjreedy@udel.edu> - 2012-09-06 21:53 -0400
Re: Bitshifts and "And" vs Floor-division and Modular Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-07 02:00 +0000
Re: Bitshifts and "And" vs Floor-division and Modular Grant Edwards <invalid@invalid.invalid> - 2012-09-07 14:19 +0000
Re: Bitshifts and "And" vs Floor-division and Modular rusi <rustompmody@gmail.com> - 2012-09-06 20:38 -0700
Re: Bitshifts and "And" vs Floor-division and Modular Paul Rubin <no.email@nospam.invalid> - 2012-09-06 21:32 -0700
Re: Bitshifts and "And" vs Floor-division and Modular rusi <rustompmody@gmail.com> - 2012-09-07 09:59 -0700
Re: Bitshifts and "And" vs Floor-division and Modular Dave Angel <d@davea.name> - 2012-09-07 13:12 -0400
csiph-web