I used the following code to measure the running time of my program,
Code:
public static void main(String[] args) {
String a = "agtacgtcatacgtctagtactacgttca";
String b = "gtatccctagactsgtatcatacgtctat";
long startTime = System.nanoTime();
//This method call computes the Longest Common Sequence of the given 2 strings.
System.out.println(LCS.Linear.computeLCS(a, b));
long endTime = System.nanoTime();
System.out.println("Took "+(endTime - startTime) + " ns");
}
Sample Outputs for same input:
Run 1:
gtacctagctgtactacgtta
Took 1971471 ns
Run 2:
gtacctagctgtactacgtta
Took 2242336 ns
Why is the difference in running time each time?
How to find the actual running time of that method call?