C++ calculating time intervals

后端 未结 5 1396
情歌与酒
情歌与酒 2021-01-22 08:05

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:

5条回答
  •  自闭症患者
    2021-01-22 08:19

    I bet your printing so much to stdout that old prints are getting buffered. The buffer is growing and the output to the console can't keep up with your tight loop. By adding the sleep you're allowing the buffer some time to flush and catch up. So even though its 8 seconds into your program, your printing stuff from 8 seconds ago.

    I'd suggest putting the actual timestamp into the print statement. See if the timestamp is lagging significantly from the actual time.

提交回复
热议问题