Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28675
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-09-06 20:38 -0700 |
| References | <d8d77115-dcb2-4769-a592-5fca0fc264bc@googlegroups.com> |
| Message-ID | <fc040467-53df-43bf-bca2-c43d3c7f5991@sd5g2000pbc.googlegroups.com> (permalink) |
| Subject | Re: Bitshifts and "And" vs Floor-division and Modular |
| From | rusi <rustompmody@gmail.com> |
On Sep 7, 5:01 am, jimbo1qaz <jimmyli1...@gmail.com> 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? On an 8086/8088 a MUL (multiply) instruction was of the order of 100 clocks and a DIV nearly 200 compared to ADD, OR etc which were something like 8 (IIRC -- this is decades-stale knowledge) On most modern processors (after the pentium) the difference has mostly vanished. I cant find a good data sheet to quote though -- one of the sad things about modern processors is that the clocks which were politely offered by intel earlier have now stopped presumably because cache-(in)coherence, pipelining etc are more likely to dominate the number of clocks than the specific instruction. This question is interesting to a programmer but meaningless at the python level (as others have pointed out). If it still interests you, work at the C (or still better assembly) level and use a more finegrained timer measure -- the finest being the RDTSC instruction.
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