View Single Post
Old 09-06-2005, 01:48 PM   #1 (permalink)
Dilbert1234567
Devils Cabana Boy
 
Dilbert1234567's Avatar
 
Location: Central Coast CA
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
Dilbert1234567 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73