I am trying to measure how much time takes serial program to reverse an array. My code:
#include <time.h>
int main() {
int n = 100000;
int c, d, a[n], b[n];
clock_t start, end;
for (c = 0; c < n ; c++)
a[c] = c;
start = clock();
for (c = n - 1, d = 0; c >= 0; c--, d++)
b[d] = a[c];
end = clock();
printf("Number of seconds: %f\n", (end-start)/(double)CLOCKS_PER_SEC );
return 0;
}
However, it is always takes 0.000000 seconds to run. Why? If I increase n
, I get segmentation errors.