As part of an assignment, we have to write a Quicksort algorithm, and then verify it's time complexity.
I am trying to time how long it takes to run the quickSort function, but it keeps returning 0.
Here is a snippet of the code
.
.
#include <time.h>
.
.
int main()
{
time_t startTime, endTime;
double stopwatch;
.
.
startTime = clock();
quickSort(nums, 0, size-1); //sorts array
endTime = clock();
stopwatch = endTime - startTime;
cout << "It took " << stopwatch << "milliseconds to execute quickSort" << "\n";
.
.
Even when n is quite large, it still returns 0. I'm guessing that the function is completed very quickly by the computer, and this might be rounded to 0.
Is there anyway I can time this, in order to verify that it has time complexity of O(n logn) (in best cases).
I've tried using the difftime(endTime, startTime) function but it gives the exact same result. I've also tried using time(NULL) instead of clock(), but again it yielded the same result.
I think that I might need to run the code 1,000 times (for instance), then divide by 1,000 and get an average, but I'm not sure how I could do this.
Thanks!