RE: VC.NET 'Optimization'

"Ken Noland" <[email protected]> Mon, 11 Apr 2005 11:42:45 -0400
Newsgroups gmane.games.devel.windows
Message-ID <[email protected]>
Yeah, I have and there is no immediate fix around this unless you want
to turn all optimizations off(hence the reason it works fine in debug
mode). 

-Ken Noland

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of
yogiwp
Sent: Monday, April 11, 2005 9:47 AM
To: [email protected]
Subject: [GD-Windows] VC.NET 'Optimization'

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




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_id=555


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Gamedevlists-windows mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gamedevlists-windows
Archives:
http://sourceforge.net/mailarchive/forum.php?forum_idU5