Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-07 Thread Dave Angel
On 09/07/2012 12:59 PM, rusi wrote: > On Sep 7, 9:32 am, Paul Rubin wrote: >> rusi writes: >>> On an 8086/8088 a MUL (multiply) instruction was of the order of 100 >>> clocks ... On most modern processors (after the pentium) the >>> difference has mostly vanished. I cant find a good data sheet

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-07 Thread rusi
On Sep 7, 9:32 am, Paul Rubin wrote: > rusi writes: > > On an 8086/8088 a MUL (multiply) instruction was of the order of 100 > > clocks ...  On most modern processors (after the pentium) the > > difference has mostly vanished.  I cant find a good data sheet to > > quote though > > See http://www.

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-07 Thread Grant Edwards
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,

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-07 Thread Mark Lawrence
On 07/09/2012 02:08, Cameron Simpson wrote: On 07Sep2012 01:30, Mark Lawrence wrote: | On 07/09/2012 01:01, 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

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Paul Rubin
rusi writes: > On an 8086/8088 a MUL (multiply) instruction was of the order of 100 > clocks ... On most modern processors (after the pentium) the > difference has mostly vanished. I cant find a good data sheet to > quote though See http://www.agner.org/optimize/ : 4. Instruction tables: L

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread rusi
On Sep 7, 5:01 am, 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? On an 8086/8088 a MUL (multiply) instruction was of the order of 100 c

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2012 18:30:48 -0700, jimbo1qaz wrote: > 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 |= Python (like most languages) doesn't have a "set thi

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2012 17:01:12 -0700, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? Does it matter? If you ever find yourself writing an application where the difference between 0.0476 microseconds and 0.0473 microseconds matters to you, Python is probably the wrong langua

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Terry Reedy
On 9/6/2012 8:01 PM, 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? Yes, meaningless, yes, and no. I would do what seems sensible to you in t

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Dave Angel
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

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Dave Angel
On 09/06/2012 08:01 PM, jimbo1qaz wrote: > Is it faster to use bitshifts or floor division? Yes, and yes. Without doing any measurement, I'd expect that in CPython, it makes negligible performance difference for ordinary ints (under 2**31, more or less). Ordinary ints can be done with single inst

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread jimbo1qaz
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

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Cameron Simpson
On 07Sep2012 01:30, Mark Lawrence wrote: | On 07/09/2012 01:01, 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? | | Why don't you use

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread jimbo1qaz
On Thursday, September 6, 2012 5:30:05 PM UTC-7, Mark Lawrence wrote: > On 07/09/2012 01:01, 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 con

Re: Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread Mark Lawrence
On 07/09/2012 01:01, 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? Why don't you use the timeit module and find out for yourself? -- Chee

Bitshifts and "And" vs Floor-division and Modular

2012-09-06 Thread jimbo1qaz
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? -- http://mail.python.org/mailman/listinfo/python-list