[GD-Windows] VC.NET 'Optimization'
Brought to you by:
vexxed72
From: yogiwp <yo...@gm...> - 2005-04-11 13:49:43
|
Hi all, I've just waste alot of time debugging, and surprised that the root of problem come from VC.NET 2003 reordering stuff too aggresively. This piece of code is supposed to measure time spent in fibonacci(): ---------------------------------------------------- timer.Restart(); int fib = fibonacci( 42 ); float msTime = timer.GetElapsed(); printf( "time=%f, result=%d\n", msTime, fib ); ---------------------------------------------------- But the optimizer decided to move the fibonacci() call just before printf() and after GetElapsed(), causing the timer to measure nothing. Of course the bug does not manifest in debug builds, which made my head hurt even more :( The fix is simply changing the last line to: printf( "time=%f, result=%d\n", timer.GetElapsed(), fib ); Anyone got bitten by this before? This is a bug, right? Yogi Wahyu Prasidha |