29 using dataElementType = std::pair<std::string, TimerResultsData>;
30 bool more_second_sec(
const dataElementType& lhs,
const dataElementType& rhs)
32 return lhs.second.seconds() > rhs.second.seconds();
36 std::mutex stdCoutLock;
47 std::vector<dataElementType> data;
55 std::sort(data.begin(), data.end(), more_second_sec);
58 std::lock_guard<std::mutex> l(stdCoutLock);
60 std::cout << std::endl;
63 for (std::vector<dataElementType>::const_iterator iter=data.cbegin(); iter!=data.cend(); ++iter) {
64 const double sec = iter->second.seconds();
65 const double secAverage = sec / (double)(iter->second.mNumberOfResults);
66 bool hasParent =
false;
73 const std::string::size_type pos = iter->first.rfind(
"::");
74 if (pos != std::string::npos)
75 hasParent = std::any_of(data.cbegin(), data.cend(), [iter,pos](
const dataElementType& d) {
76 return d.first.size() == pos && iter->first.compare(0, d.first.size(), d.first) == 0;
80 overallData.
mClocks += iter->second.mClocks;
82 std::cout << iter->first <<
": " << sec <<
"s (avg. " << secAverage <<
"s - " << iter->second.mNumberOfResults <<
" result(s))" << std::endl;
87 const double secOverall = overallData.
seconds();
88 std::cout <<
"Overall time: " << secOverall <<
"s" << std::endl;
106 : mStr(std::move(str))
107 , mTimerResults(timerResults)
108 , mStart(std::clock())
109 , mShowTimeMode(showtimeMode)
114 : mStr(std::move(filename))
115 , mStopped(!fileTotal)
126 const std::clock_t end = std::clock();
127 const std::clock_t diff = end -
mStart;
130 const double sec = (double)diff / CLOCKS_PER_SEC;
131 std::lock_guard<std::mutex> l(stdCoutLock);
132 std::cout <<
mStr <<
": " << sec <<
"s" << std::endl;
134 const double sec = (double)diff / CLOCKS_PER_SEC;
135 std::lock_guard<std::mutex> l(stdCoutLock);
136 std::cout <<
"Check time: " <<
mStr <<
": " << sec <<
"s" << std::endl;
virtual void addResults(const std::string &str, std::clock_t clocks)=0
void addResults(const std::string &str, std::clock_t clocks) override
void showResults(SHOWTIME_MODES mode) const
std::map< std::string, TimerResultsData > mResults
TimerResultsIntf * mTimerResults
const SHOWTIME_MODES mShowTimeMode
Timer(std::string str, SHOWTIME_MODES showtimeMode, TimerResultsIntf *timerResults=nullptr)
bool startsWith(const std::string &str, const char start[], std::size_t startlen)