To calculate the running time for your initial phase space search algorithm, try the following ways of using the time_t type
#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 (in);
Testobj. TEST ();
Testobj. TEST ();
Testobj. Fillrandomdets ();
Testobj.evolute (1000, 0.9);
cout << "--------------------------------------------" << Endl;
Time (&finish);
Double duration = difftime (finish, start);
cout << "--> Time:" << duration << "s" << Endl;
cout << "--------------------------------------------" << Endl;
return 0;
}
This realization method can correctly calculate the core part of the algorithm consumes 234 seconds of walltime. The attempt to use the clock_t type before this is
#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 (in);
Testobj. TEST ();
Testobj. TEST ();
Testobj. Fillrandomdets ();
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;
}
This code has been running for only 11 seconds, obviously not. The reason for this result is not yet clear, perhaps because the algorithm in the implementation of the process of frequent calls to other external programs to obtain some calculation results.
The above is a small series for you to bring the timer time_t and clock_t two ways to achieve (recommended) all content, I hope that we support cloud Habitat Community ~