Here is my code in my main that calculates for the time difference of selectionSort() using nanoTime():
System.out.println("Start time :: " + test.start());
test.selectionSort();
System.out.println("End time :: " + test.end());
System.out.println(test);
System.out.print("Time took to run selectionSort() == ");
System.out.println((test.getElapsedTime()) + " nanoseconds");
and my start(), end(), and getElapsedTime() methods are:
public long start(){
startTime = System.nanoTime();
return startTime;
}
public long end(){
endTime = System.nanoTime();
return endTime;
}
public long getElapsedTime(){
return end() - start();
}
After running this program, the output is:
5 2 9 7 4 3 0 1 6 8
Start time :: 915929737160723
End time :: 915929737309925
0 1 2 3 4 5 6 7 8 9
Time took to run selectionSort() == -5921 nanoseconds
How come the getElapsedTime() method returns a negative number when it's supposed to be a positive?