#include <stdio.h>
#include <string.h>
#include <time.h>
int main()
{
int i;
FILE *fp;
int n = 0;
int sum = 0;
fp = fopen("test.txt","r");
/*count real, user, and sys time */
clock_t start = clock();
while(!feof(fp))
{
fscanf(fp, "%d", &n);
sum += n;
}
if(sum > 100)
printf("Great.\n");
else
printf("...\n");
printf("Sum: %d", sum);
fclose(fp);
/*End...*/
clock_t end = clock();
float seconds = (float)(end - start) / CLOCKS_PER_SEC;
printf("\nTime: %lf\n", seconds);
return 0;
}
In test.txt:
1 2 3 4 5
6 7 8 9 10
Output:
sh-4.3$ main
...
Sum: 55
Time: 0.000102
My goal is to count time of real, user and sys for output.
So, is this Time considered as real time?
If yes, how to calculate user and sys time here?