clock_gettime()

clock_gettime( ) 提供了納秒的精確度,給程序計時可是不錯哦;

函數的原型如下:

int clock_gettime(clockid_t clk_id, struct timespect *tp);

clockid_t clk_id用於指定計時時鐘的類型,對於我們Programmr以下三種比較常用:

CLOCK_REALTIME, a system-wide realtime clock.
CLOCK_PROCESS_CPUTIME_ID, high-resolution timer provided by the CPU for each process.
CLOCK_THREAD_CPUTIME_ID, high-resolution timer provided by the CPU for each of the threads.
CLOCK_REALTIME, a system-wide realtime clock.
CLOCK_MONOTONIC
CLOCK_PROCESS_CPUTIME_ID, high-resolution timer provided by the CPU for each process.
CLOCK_THREAD_CPUTIME_ID, high-resolution timer provided by the CPU for each of the threads.
struct timespect *tp用來存儲當前的時間,其結構如下:
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */

};

原文http://igaozh.iteye.com/blog/1675767

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章