Re: [Algorithms] Shifting or Multiplication....
Brought to you by:
vexxed72
From: Neil S. <ne...@r0...> - 2000-12-29 03:06:32
|
> I was wondering if anyone could clear up something. Algorithmically, is > bitshifting or using multiplication faster?? Now, I know this sounds like a > subjective question, as some will undoubtadly say, it depends on the > compiler and what it translates the code into. Lets take it down to the ASM > level. It is reasonable to expect that, on most (all, AFAIK) systems, shifting will be as fast or faster than a multiply, especially as integer multiplies are done with a "shift-add" sequence on older CPUs. Therefore, in cases where it is natural to do a shift (eg. masking values in a compound type, like a color), a shift is a good thing to use. In other cases, as Corrine has stated, it is nothing to get too stressed about. - Neil |