Compiling time

Hi there. I have a double called "max_translate" in my program that is used in this part of code:

1
2
3
const double delta_x = rand(-max_translate, max_translate);
      const double delta_y = rand(-max_translate, max_translate);
      const double delta_z = rand(-max_translate, max_translate);


Previously I just had max_translate set as a constant double and the program worked fine. However, I am now wanting to calculate a new value of max_translate depending on a ratio of successful to rejected moves elsewhere in the program:

1
2
3
4
5
6
7
8
9
	double ratio = (naccept/(naccept+nreject));
	if (ratio>0.25)
        {
            max_translate=max_translate*1.05;				
        }
        if (ratio<0.20)
        {
            max_translate=max_translate*0.95;	
        }


However, just by adding this simple bit of code, the program has moved from being extremely quick to a virtual stand still.

Any ideas why this might be?

Cheers.
Well, with the amount of detail you've given us, it's hard to tell. I imagine the cost of fetching max_translate from memory vs. getting it inside the floating point instruction is piling up.
Another possibility is that your previous version used exactly as many floating point registers as your CPU has, but now the program has to swap values in and out of memory. I've seen a function drop in performance by a factor of 4, I think, after adding one bitwise operation on one more variable.
Topic archived. No new replies allowed.