Hello,
Are nested function calls inefficient (or inherently evil)? In Delphi
I've seen small but significant performance improvements by always
declaring a local variable and 'unwrapping' the nested calls, but I'm not
convinced it is necessarily so in c#. So for example:
public struct TideValue {
public TideValue( double Time, double Height )
{
time = Time;
height = Height;
}
public double time;
public double height;
}
public class TideClass {
private ArrayList Values;
private double GetTideValue ( double aTime )
{
do something
return something
}
public void CalcTides( double starttime, double endtime )
{
while ( starttime < endtime )
{
Values.Add( new TideValue( curtime, GetInstantHeight( curtime ) )
);
}
}
}
or will this be more efficient;
public void CalcTides( double starttime, double endtime )
{
while ( starttime < endtime )
{
double height = GetInstantHeight( curtime );
TideValue value = new TideValue( curtime, height )
Values.Add( value );
}
}
I'm going to be thousands of these, so small improvements addup. I will,
of course, be doing some tests once the code works, but I'm curious to
know what the rules are for this sort of thing in general.
Thanks
Marc Pelletier