#include <stdio.h>
#include <time.h>
#include <stdint.h>
//接受开始结束时间,返回差值
double compute_time(struct timespec start, struct timespec end)
{
double diffSec;
diffSec = (double)(end.tv_sec - start.tv_sec) + ((double)(end.tv_nsec - start.tv_nsec) / (double)1000000000);
printf(“diffSec %.12lf ns \n”, diffSec);
return diffSec;
}
int main()
{
int num = 0;
int endNum = 102410241024;
struct timespec start, end;
clock_gettime(CLOCK_MONOTONIC, &start);
while(num < endNum)
{
num++;
}
clock_gettime(CLOCK_MONOTONIC, &end);
compute_time(start, end);
printf(“end num= %llu\n”,num);
}