Hi,
Is the java compiler smart enough to optimize loop below (by extracting the
Double average = new Double( totalTime / callCount );
out of the for loop?
public double computeSD( Set values, int callCount, long totalTime ) {
double diffs = 0.0d;
for( Iterator i=values.iterator(); i.hasNext(); ) {
double value = ( ( Double )i.next() ).doubleValue();
Double average = new Double( totalTime / callCount );
diffs += ( value – average.doubleValue() ) * ( value – average.doubleValue() );
}
double variance = diffs / callCount; return Math.sqrt( variance );
}