开发者

Current microsecond time in C?

How can I print curren开发者_Go百科t microseconds time in C on Unix platform?


In Linux and BSDs, you can use the gettimeofday() function. This populates a timeval struct which has a field for seconds since the epoch and a field for microseconds. This function is deprecated. The higher resolution clock_gettime() is the favored replacement, however Mac OS X does not implement it. I'm not sure if Windows implements either of these.


There is no portable (multiplatform) way to get that number. On Linux (or other POSIX systems) for example there is the call gettimeofday that provides exactly that precision (accuracy however will depend if that timing is available and implemented on the specific hardware).


The C standard doesn't provide a standard means for that. However the clock() function returns time in CLOCK's. there are CLOCKS_PER_SEC CLOCK's in a second. On my machine and implementation, CLOCKS_PER_SEC is defined as 1000. Both clock and CLOCKS_PER_SEC are defined in <time.h>. Hope this helped


If you are on linux, I would check out this site: http://rabbit.eng.miami.edu/info/functions/time.html Particularly the 'gettimeofday' function. Which you can pass a structure, and get the time of day in microseconds.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜