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. -- http://mail.python.org/mailman/listinfo/python-list