I want to calculate time intervals (in 1/10th of 1 second) between some events happening in my program. Thus I use clock
function for these needs like follows:
clock_t begin;
clock_t now;
clock_t diff;
begin = clock();
while ( 1 )
{
now = clock();
diff = now - begin;
cout << diff / CLOCKS_PER_SEC << "\n";
//usleep ( 1000000 );
};
I expect the program to print 0
for 1 second, then 1
for 1 sec., then 2
for 1 sec. and so on... In fact it prints 0
for about 8 seconds, then 1
for about 8 seconds and so on...
By the way, if I add usleep
in order program prints only 1 time per second, it prints only 0
all way long...
Great thanks for help!