difftime64()- 计算时间差异
格式
#include <time.h>
double difftime64(time64_t time2, time64_t time1);语言级别
ILE C 扩展
线程安全
是
描述
difftime64() 函数计算 time2 与 time1之间的差值 (以秒计)。
返回值
difftime64() 函数以双精度数形式返回从 time1 到 time2 的耗用时间 (以秒为单位)。 类型 time64_t 在 <time.h>中定义。
示例
此示例显示了使用
difftime64()的计时应用程序。 此示例计算查找从 2 到 10 000 的素数所花费的平均时间。#include <time.h>
#include <stdio.h>
#define RUNS 1000
#define SIZE 10000
int mark[SIZE];
int main(void)
{
time64_t start, finish;
int i, loop, n, num;
time64(&start);
/* This loop finds the prime numbers between 2 and SIZE */
for (loop = 0; loop < RUNS; ++loop)
{
for (n = 0; n < SIZE; ++n)
mark [n] = 0;
/* This loops marks all the composite numbers with -1 */
for (num = 0, n = 2; n < SIZE; ++n)
if ( ! mark[n])
{
for (i = 2 * n; i < SIZE; i += n)
mark[i] = -1;
++num;
}
}
time64(&finish);
printf("Program takes an average of %f seconds "
"to find %d primes.\n",
difftime64(finish,start)/RUNS, num);
}
/******************** Output should be similar: *****************
The program takes an average of 0.106000 seconds to find 1229 primes.
*/
相关信息
- asctime ()-将时间转换为字符串
- asctime_r ()-将时间转换为字符串 (可重新启动)
- ctime ()-将时间转换为字符串
- ctime64()-将时间转换为字符串
- ctime64_r()-将时间转换为字符串 (可重新启动)
- ctime_r ()-将时间转换为字符串 (可重新启动)
- difftime ()-计算时间差异
- gmtime ()-转换时间
- gmtime64()-转换时间
- gmtime64_r()-转换时间 (可重新启动)
- gmtime_r ()-转换时间 (可重新启动)
- localtime ()-转换时间
- localtime64()-转换时间
- localtime64_r()-转换时间 (可重新启动)
- localtime_r ()-转换时间 (可重新启动)
- mktime ()-转换本地时间
- mktime64()-转换本地时间
- strftime ()-将日期/时间转换为字符串
- time ()-确定当前时间
- time64()-确定当前时间
- <time.h>