# 计时器的 time_t 和 clock_t 两种实现方法

想给自己初步完成的相空间搜索算法计算一下运行时间，于是尝试了如下使用 time_t 类型的方式

#include <stdlib.h>
#include <iostream>
#include <time.h>
#include "StateFunctions.h"

using namespace std;

int main(int argc, char** argv)
{
time_t start, finish;

time(&start);

StateFunctions testobj(22, 22);
testobj.TEST();
testobj.TEST();
testobj.FillRandomDets(200);
testobj.evolute(1000, 0.9);

cout << "--------------------------------------------" << endl;
time(&finish);
double duration = difftime(finish, start);
cout << "--> time: " << duration << " s" << endl;
cout << "--------------------------------------------" << endl;

return 0;
}

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

using namespace std;

int main(int argc, char** argv)
{
clock_t start, finish;
start = clock();

StateFunctions testobj(22, 22);
testobj.TEST();
testobj.TEST();
testobj.FillRandomDets(200);
testobj.evolute(1000, 0.9);

cout << "--------------------------------------------" << endl;
finish = clock();
double duration = (double)(finish - start) / CLOCKS_PER_SEC;
cout << "--> time: " << duration << " s" << endl;
cout << "--------------------------------------------" << endl;

return 0;
}