I have Java code that is a combination of a while loop and recursion. The problem that we are facing is that calling the method below takes almost 8 times longer in the unix window [HP ProLiant BL460c G7] than the window [Intel Xeon CPU E5-1650, 64 bit Windows 7]. Any ideas on how to improve runtime in a Unix block. We are using JDK 1.6_43 [64 bit]
protected Date abc(int n, Date date)
{
long tStart = System.currentTimeMillis();
if (n > 0)
{
while (n > 0)
{
--n;
date = getNextExchangeDateUnadjusted(date);
}
return date;
}
else
{
Date nextExchangeDate = getNextExchangeDateUnadjusted(date);
Date previousExchangeDate = getNextExchangeDateUnadjusted(date);
while (!abc( -n + 1, previousExchangeDate).equals(nextExchangeDate))
{
date = date.addDays( -14);
previousExchangeDate = getNextExchangeDateUnadjusted(date);
}
return previousExchangeDate;
}
}
EDIT:
Below is the code for the method getNextExchangeDateUnadjustedthat is called above
public Date getNextExchangeDateUnadjusted(Date date) {
Date thirdWednesdayInMonth = date.getThirdWednesdayInMonth();
if (thirdWednesdayInMonth.after(date)) {
return thirdWednesdayInMonth;
}
return date.addMonths(1).getThirdWednesdayInMonth();
}
}
I also want to add that this code spends the maximum time in this part:
while (!abc( -n + 1, previousExchangeDate).equals(nextExchangeDate))
{
date = date.addDays( -14);
previousExchangeDate = getNextExchangeDateUnadjusted(date);
}
EDIT2:
Unix, , , "Retained Heap" 1 4,5 , . , . Windows, XSS.