RE: [GD-Windows] VC.NET 'Optimization'
Brought to you by:
vexxed72
From: Grills, J. <jg...@so...> - 2005-04-12 21:35:47
|
Perhaps I missed something earlier on since I haven't been following this thread that closely, but I don't see your point. Looking at the two code statements quoted: timer.Restart(); printf( "time=3D%f, result=3D%d\n", timer.GetElapsed(), fibonacci(42)); The compiler could call the functions in this order: timer.Restart() timer.GetElapsed() fibonacci() printf() Or it could call them in this order: timer.Restart() fibonacci() timer.GetElapsed() printf() Only the latter one would have the timer include the fibonacci() call time, because it's made between the timer.Restart() and timer.GetElapsed(). To be safe, as you said, the fibonacci() call would have to be made in a statement after the timer.Restart() but before the printf() containing the timer.GetElapsed(); j -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Lewin, Gareth Sent: Tuesday, April 12, 2005 4:12 PM To: gam...@li... Subject: RE: [GD-Windows] VC.NET 'Optimization' Again, the order doesn't matter, the fib function has no side effects. His goal in this specific case is to measure the speed of his fib function, so contextually changing the order the params are passed will work. If the order mattered, then fib would have been called outside the printf scope.=20 -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Grills, Jeff Sent: Tuesday, April 12, 2005 12:17 PM To: gam...@li... Subject: RE: [GD-Windows] VC.NET 'Optimization' Maybe on some compilers, but it's not guaranteed. The order of argument evaluation to functions is not specified by the C++ standard - it's left up to the implementations. j -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of Lewin, Gareth Sent: Tuesday, April 12, 2005 2:02 PM To: gam...@li... Subject: RE: [GD-Windows] VC.NET 'Optimization' I fail to see why this worries you, the optimiser is making a (valid) assumption about your code, and generating the fastest sequence it can. As a side note, just flip the order of your params to printf, that should give you want you want.=20 -----Original Message----- From: gam...@li... [mailto:gam...@li...] On Behalf Of yogiwp Sent: Tuesday, April 12, 2005 11:52 AM To: gam...@li... Subject: Re: [GD-Windows] VC.NET 'Optimization' > ---------------------------------------------------- > timer.Restart(); > printf( "time=3D%f, result=3D%d\n", timer.GetElapsed(), = fibonacci(42)=20 > ); > ---------------------------------------------------- |