The following code was run in codeblocks, gcc compiler.
#include <sys/time.h>
#include<stdio.h>
int sumN(int n) {
int i,sum;
for(i=0; i<n; i++) {
sum += i;
}
return sum;
}
int main() {
struct timeval stop, start;
int i;
for(i=0; i<10000;i+=100)
{
gettimeofday(&start, NULL);
sumN(i);
gettimeofday(&stop, NULL);
printf("%d : %lu\n",i, stop.tv_usec - start.tv_usec);
}
return 0;
}
and I get the following output. Is there an issue with the gettimeofday function? Or the output is right? I need to also plot a graph based on multiple input size for function and the time taken for the function execution.