C语⾔的⼏种不同的计时函数1. cloc只爱你一个人
k()函数⽅法
clock_t time1,time2;
time1 = clock();
time2 = clock();
double run_面膜时间
time = (double)世界上最大的单位
(time2-time1)/CLOCKS_PER_SEC;
printf("runtime = %f\n",run_time);
2. 系统时间⽅法
⾸先包含头⽂件
#include <sys/time.h>
代码部分:
struct timeval TimeValue_Start;
struct timezone TimeZone_Start;
struct timeval TimeValue_Final;
struct timezone TimeZone_Final;
long time_start, time_end;
double time_overhead;
gettimeofday(&TimeValue_Start, &TimeZone_Start);//开始计时
........//开始计算
gettimeofday(&TimeValue_Final, &TimeZone_Final);//结束计时
time_start = TimeValue_Start.tv_c * 1000000 + TimeValue_Start.tv_uc;
time_end = TimeVal漫画男生
ue_Final.tv_c * 1000000 + TimeValue_Final.tv_u猪腰的功效与作用
c;
time_over北京市旅游景点
head = (time_end - time_start)/1000000.0;
printf("\n\n\t\t Time in Seconds (T) : %lf",time_overhead);//输出运⾏时间
3.OpenMP上的计时函数
OpenMP程序的计时要么使⽤omp的取时间函数(⽅法3)要么使⽤系统时间(⽅法2)反正不能使⽤clock(⽅法1),clock()函数的计时好像是所以线程的时间,这样周杰伦彩虹歌词
会有OpenMP没有加速的错觉。
double start = omp_get_wtime();
.........//计算
double end = omp_get_wtime();
do赠送的英语短语
uble runtime = end-start;
printf("runtime = %f\n",runtime);
4.MPI上的计时函数
double 大学心理健康论文
read_file_start,read_file_end;
read_file_start = MPI_Wtime();//开始读⽂件
.......//开始计算
read_file_end= MPI_Wtime();//读⽂件结束
printf("rank%d\tread_file_time:%f\n",rank,read_file_end-read_file_start);