当评价一个算法性能时,linux下就提供了这样的一个函数: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_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.
#
include
<
stdio
.
h
>
# include < time . h >
struct timespec diff
# include < time . h >
struct timespec diff