Created
September 6, 2012 01:07
-
-
Save ahmadyan/3649349 to your computer and use it in GitHub Desktop.
tick-tock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <string> | |
#include "utils.h" | |
using namespace std; | |
namespace utils { | |
double initial_time = clock(); | |
time_t t1=0,t2=0,t3=0; | |
double final_time = 0; | |
double total_time = 0; | |
/* | |
the tick & tock functions are used toghether (usually in main() ) to | |
calculate the time used by a specific function. | |
they should be used like this: | |
utils::tick(); | |
f1(); | |
f2(); | |
f3(); | |
utils::tock("name of process/function", result_file_pointer); | |
*/ | |
void tick(){ | |
initial_time = clock(); | |
time(&t1); | |
} | |
void tock(std::string processName, FILE* resultfp){ | |
final_time = clock(); | |
total_time = (double) (final_time - initial_time) / (double) CLOCKS_PER_SEC ; | |
time(&t2); | |
t3 = t2 - t1; | |
if (t3>1000) total_time = t3; | |
cout << endl << "[time-report] Time required to " << processName << " is: " << total_time << " seconds"<<endl; | |
if(resultfp!=NULL) fprintf(resultfp, "\n[time-report] Time required to compute %s is: %f seconds.\n", processName.c_str(), total_time); | |
} | |
} // namespace utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <string> | |
#include <iostream> | |
/// namespace to contain the used utilities | |
namespace utils { | |
void tick(); | |
void tock(std::string processName,FILE* resultfp); | |
} // namespace utils |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment