I was wondering if calculating a method's execution time this way is accurate:
public class GetExecutionTimes {
public static void main(String args[]) {
long startTime = System.currentTimeMillis();
GetExecutionTimes ext = new GetExecutionTimes();
ext.callMethod();
long endTime = System.currentTimeMillis();
System.out.println("Total elapsed time in execution of"
+ " method callMethod() is :" + (endTime - startTime));
}
public void callMethod() {
System.out.println("Calling method");
for (int i = 1; i <= 10; i++) {
System.out.println("Value of counter is " + i);
}
}
}
More specifically: Will the time difference be the same if I execute in different conditions?
If not how can I make this calculate more precise?