RE: VC.NET 'Optimization'
"Simon O'Connor" <[email protected]> Mon, 11 Apr 2005 23:05:12 +0100
| Newsgroups | gmane.games.devel.windows |
|---|---|
| Organization | SC3D |
| Message-ID | <[email protected]> |
Simply re-ordering the source without forcing optimisations off isn't guaranteed to do what you expect. Contrived example: imagine your profiling code calls QueryPerformanceFrequency() and then code being profiled later on makes a call to QueryPerformanceFrequency(); it's feasible that an optimiser could detect two calls to that same Windows function and optimise them into one call thus totally skewing your results. Personally (when not using an already proven profiler) I'd always declare the timer object and even msTime as "volatile" to ensure the compiler doesn't consider them for optimization. Alternatively you can use #pragma optimize to control exactly which code does and doesn’t get optimised. BTW: I'm not entirely sure whether that's a compiler bug or a valid optimisation - it depends what your Restart() function does. > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On > Behalf Of yogiwp > Sent: 11 April 2005 14:47 > 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 > > > > -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.6 - Release Date: 11/04/2005 ------------------------------------------------------- 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