Question: How come when I run this in Visual studio the run time in milliseconds is always 0 seconds but if I compile and run on
How come when I run this in Visual studio the run time in milliseconds is always 0 seconds but if I compile and run on some online compiler it gives realistic numbers
#include
const int sizeArray = 16000;
// Insertion sort function void insertionSort(int arr[], int n) { for (int i = 1; i < n; i++) { int key = arr[i]; int j = i - 1; while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j--; } arr[j + 1] = key; } }
int main() { int arr[sizeArray]; srand(time(NULL)); for (int j = 0; j < sizeArray; j++) { arr[j] = rand() % 1000; // Initialize array with random values between 0 and 999 }
// Time insertion sort clock_t start = clock(); insertionSort(arr, sizeArray); clock_t end = clock(); cout << "Insertion sort time: " << (end - start) << " milliseconds" << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
