-
-
Save 345161974/5d9e9638e0e95fb4c85c36fe18acdfd7 to your computer and use it in GitHub Desktop.
Calculate diff of two struct timespec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
void timespec_diff(struct timespec *start, struct timespec *stop, | |
struct timespec *result) | |
{ | |
if ((stop->tv_nsec - start->tv_nsec) < 0) { | |
result->tv_sec = stop->tv_sec - start->tv_sec - 1; | |
result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000; | |
} else { | |
result->tv_sec = stop->tv_sec - start->tv_sec; | |
result->tv_nsec = stop->tv_nsec - start->tv_nsec; | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
更多可以参考:
http://blog.csdn.net/liu44235/article/details/37692635
http://www.cnblogs.com/chezxiaoqiang/archive/2012/03/23/2674386.html
http://www.cnblogs.com/spinsoft/p/3767549.html