Bitshifts and "And" vs Floor-division and Modular

jimbo1qaz jimmyli1528 at gmail.com
Thu Sep 6 21:30:48 EDT 2012


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.



More information about the Python-list mailing list