(Using Java)
I’m testing sorting arrays to see literally how fast different sorting arrays take. I want to weed out the erroneous times, so ideally I would like to start a timer, run the sort in a loop of say 100 times, stop the timer, then divide by 100 to get a pretty accurate measure.
The problem is if I were to loop the same array, it’ll sort properly the first time, then each sort after, it’ll keep sorting the already sorted array, which isn’t what I want.
Maybe I’m missing an obvious solution, but is there any way I can make it keep sorting the same initial randomized array?
I thought about reassigning the newly sorted array back to the initial random array each time, but that would mess up my timer..
thanks for any suggestions
what i would like to do:
startTime = System.nanoTime();
for(int i=0; i<cntr; i++) {
sort array
}
endTime = System.nanoTime();
time = (endTime - startTime)/cntr;
You can make a copy before you start sorting, and then copy from that stored copy into the array being sorted in each iteration of the loop.