返回值
此函数将两倍的时间差(time1-time2)作为双精度值返回。
示例
以下示例显示difftime函数的用法-
#include <stdio.h>
#include <time.h>
int main () {
time_t start_t, end_t;
double diff_t;
printf("Starting of the program...\n");
time(&start_t);
printf("Sleeping for 5 seconds...\n");
sleep(5);
time(&end_t);
diff_t = difftime(end_t, start_t);
printf("Execution time = %f\n", diff_t);
printf("Exiting of the program...\n");
return(0);
}
尝试一下
让我们编译并运行上面的程序,它将产生以下结果。
Starting of the program...
Sleeping for 5 seconds...
Execution time = 5.000000
Exiting of the program...