用于记录程序运行时间

 

方法一:用clock_t 

#include <time.h>
#include <iostream>

using namespace std;

clock_t begin = clock();
..............

clock_t end = clock();

double  cost = (double)(end - begin)/ (double)CLOCKS_PER_SEC * 1000;

cout << "运行时间:" << cost << "ms" << endl;

 方法二: 用time_t 

 

#include <time.h>

time_t begin;
time_t end;
begin = time(NULL);
................程序代码
end = time(NULL);

cout << "程序运行时间: " <<  end - begin << "second " << endl;

 

posted @ 2013-12-20 18:43  sndnvaps  阅读(356)  评论(0编辑  收藏  举报