English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
I want to calculate the running time of the preliminary completed phase space search algorithm, so I tried the following method 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(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; }
This implementation method can correctly calculate the time consumed by the core part of the algorithm234seconds of walltime. Before this, the implementation method using clock_t type was
#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; }
The running time obtained by this code is only11Seconds, which is obviously not correct. The reason for this result is not yet clear, perhaps because the algorithm frequently calls other external programs during execution to obtain some calculation results.
That's all for the two implementation methods of time_t and clock_t timers brought to you by the editor. I hope everyone will support and cheer for the Time Tutorial~