http://stackoverflow.com/questions/2808398/easily-measure-elapsed-time
https://github.com/picanumber/bureaucrat/blob/master/time_lapse.h
The |
if (globals::gAMInstance->enableTrans()) {
clock_t begin = clock();
std::string ostr;
raw_string_ostream ostrstream(ostr);
ostrstream << *module;
std::ofstream ofs(globals::getOutputDir(ASSEMBLY_BEFORE_TRANS_LL_FILE));
ofs << ostrstream.str();
ofs.close();
outs() << "transforming ......
";
legacy::PassManager PM;
// PM.add(new ProgTrans());
PM.run(*module);
outs() << "program transforming finished
";
outs().flush();
clock_t end = clock();
double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
std::cerr << "Program transformation spends " << std::fixed
<< std::setprecision(4) << elapsed_secs << "s.
";
// RWset RW(*globals::gCMInstance->getKModule()->module,
// shape::RWType::TRANS);
// RW.dump();
// RWset rwset(*(this->module), shape::RWType::STATE_CACHE);
// const Instruction &ins = module->begin()->back().front();
// errs() << "the live variables of " << ins << " :
";
// auto s = rwset.readset(ins);
// s.dump();
// rwset.dump();
// exit(0);
}
You can abstract the time measuring mechanism and have each callable's run time measured with minimal extra code, just by being called through a timer structure. Plus, at compile time you can parametrize the timing type (milliseconds, nanoseconds etc). Thanks to the review by Loki Astari and the suggestion to use variadic templates. This is why the forwarded function call.
According to the comment by Howard Hinnant it's best not to escape out of the chrono system until we have to. So the above class could give the user the choice to call
and be most useful for clients that
The complete code can be found here. My attempt to build a benchmarking tool based on chrono is recorded here. If C++17's
to provide for callables that are pointers to member functions. |