开发者

Is this return time in micro sec?

开发者 https://www.devze.com 2023-02-20 01:21 出处:网络
struct timeval start, end; . . . elapsedTime = (((end.tv_sec * 1000000) - (start.tv_sec * 1000000)) + (end.tv_usec - start.tv_usec));
struct timeval start, end;    
.
.
.
elapsedTime = (((end.tv_sec * 1000000) - (start.tv_sec * 1000000)) + (end.tv_usec - start.tv_usec));

I just want to double check this returns 开发者_StackOverflow社区time in micro sec..


The code is correct, but watch out for overflow. It's slightly safer to do

(end.tv_sec - start.tv_sec) * 1000000

then add in the usec difference.


Looks OK to me. I assume you actually initialize the timeval to something interesting.


yes it does... you are multipling seconds with 1000000 (usec in seconds) and adding usec. Should work

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号