On Sun, 2007-10-07 at 08:38 -0700, [EMAIL PROTECTED] wrote: > Hi, > > I have the following test program and compiled it with the -O3 in g++ > (. In "one_branch()" function, the two loops run in the same among of > the time, which means the if statement in the first loop is not > tested.
Of course, this is a constant expression (i.e. b is always true). The compiler might optimize it even without the -O3 option. > In "two_branches" function, the last loop runs a lot faster > than the other three loops, which means that the compiler does not > optimize enough for the other three cases. I'm wondering if g++ can do > better in those three cases. Is it a bug of g++? Huh, you have saved two memory access for each iteration by using a constant index (i.e., 0 instead of n). You expected the time to be less, didn't you !!! The other three cases are consuming equal amount of time, since the compiler is optimizing (and removing) the if statements, and also optimizing the multiple addition operations. -- John V. Shahid <[EMAIL PROTECTED]> _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus