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
精彩评论