On 26.02.2013 14:23, JF Gallant wrote:
> So , if I never get under zero and my operation stay simple , I can use
> cdivision to get a bit of speed.
If you only have positive integers it should not matter. If you have
signed integers you can use cdivision to get some extra speed for the
cost of mathematical correctness. But it is very rare that integer
division or modulus operators matters for the performance of an
algorithm. Examples are random number generators, compression
algorithms, or encryption/decryption, ring-buffers, and other stuff that
depends heavily on division or modulus.
> I just want to switch between 0,1,2 ( x,y,z axis ) depends on the depth
> for my simple kdtree implementation.
> I will see if they can cause problem and if the speed gain is correct.
That is speed-gain for the division, not speed gain for the whole
program! Usually it never matters, because it is just a tiny tiny part
of the run-time. For the purpose you describe here I can almost
guarantee you it will not see any difference. Premature optimization
serves no purpose. If you were writing a high-performance encryption
algorithm it could matter. If you were using modulus for indexing into a
ring-buffer in digital signal processing it could matter. But not for
swapping the splitting axis in a kd-tree.
Sturla