I think the output of following code should be excatly or near the macro CLOCKS_PER_SEC, however, the output is not very consistant.
int main(int argc, char const *argv[])
{
clock_t before = clock();
while (1) {
sleep(1);
printf("Res: %ld\n", clock() - before);
fflush(stdout);
before = clock();
}
}
Sample Output:
Res: 0
Res: 1301
Res: 1540
Res: 1597
Res: 1631
Res: 1689
Res: 1740
Res: 1783
Res: 1835
Res: 1902
Res: 1956
Res: 1981
Res: 2045
Res: 2098
Res: 2147
Res: 2207
Res: 2265
Res: 2323
I assume the clock() function only return the excution time of the code.
So, How can I measure real world time in c?