开发者

Is this return time in micro sec?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜