openmp(1)----计时

时间是用来评价一个算法或代码的重要指标。

clock_t 为时钟周期数,在并行程序中这种方式不能测量时间。

#include <time.h>
clock_t start,finish;  
start = clock();
finish = clock();
std::cout<<"完成需要 "<<finish - start<<"个时钟周期"<<std::endl;
std::cout<<"消耗时间为:"<<(finish - start)/CLOCKS_PER_SEC*1000<<"ms\n"<<std::endl;
// CLOCKS_PER_SEC 每秒德时钟周期数

double omp_get_wtime() 返回绝对时间,单位为s

#include<omp.h>
double start = omp_get_wtime( );
double end = omp_get_wtime( );

double  omp_get_wtick()   返回单个时钟周期的时间,s

#include "omp.h"
#include <stdio.h>

//获得一个时钟周期是多少秒
double wtick = omp_get_wtick( );
printf("wtick = %.16g\n1/wtick = %.16g\n", wtick, 1.0 / wtick);  // 每s的时钟周期数

猜你喜欢

转载自www.cnblogs.com/feihu-h/p/12174793.html