Hi, I'm trying to time my sorting methods for my class, and I'm unsure why the elapsed time for each one after the first is wrong, I'm updating the start and end times. I'm currently timing my merge sort.
this is what I do using command lines and save to all the running times to a text file: run_times.txt
For example: >java Insertion_sort >> run_times.txt
When I check the run_times.txt I get for example:
elapsed time: 6000ms
run time: 1000ms
run time: 1020ms
run time: 1080ms
*I know the running time of approximatley 6000ms is correct, but why are the other times not timed properly. I reset start and end times after the inner for loop done inserting 1,000,000 items. I hope it's a silly mistake I made...
public static void main(String[] args) { int array = create_array(size); long start = 0; long end = 0; for ( int j=0; i<50; i++ )//run a total of 50 times { start = System.currentTimeMillis();//restarting time after all 1 000 000 items sorted for ( int j = 0; j < 1_000_000; ++j )//turn this into a method, don't do more work by reading values from an array mergeSort(array, 1_000_000); end = System.currentTimeMillis(); System.out.println("Run time: " + (end - start) ); }