Code execution time questions
I have a bit of a problem with some code, it seems that everything i know is wrong. i am trying to clock some code exicution time and the results are puzzling me. i am clocking the difrences in calling a method vs having that method in the code it self, so it does not have make the method call. and i would think the addition of the method call would slow it down, but my results show that it speeds it up, i think adding complexity would add time, but my results say difrent, can any oen look at this code and tell me why i am getting these results?
Here is the code for the main()
int i =0;
while (i++<50000)
System.out.println(i);
long m=0;
testInt1=101;
double result2=0;
start7= System.currentTimeMillis();
while(m++<5000000000l)
result2=convertFahrToCels(testInt1);
stop7 = System.currentTimeMillis();
m=0;
start8= System.currentTimeMillis();
while(m++<5000000000l)
result2=(5 * (testInt1 - 32) / 9);
stop8 = System.currentTimeMillis();
here is the method i am comparing it to:
private static double convertFahrToCels(double fahr)
{
return (5 * (fahr - 32) / 9);
}
When I calculate the run times for the code, the method call is always about 3 times less than having the code in the loop it self. btw I know that java takes a bit to 'get warmed up' so I have a loop at the beginning of my program to warm up the JVM.
~dil
__________________
Donate Blood!
"Love is not finding the perfect person, but learning to see an imperfect person perfectly." -Sam Keen
|