Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Tsqr_TimeStats.cpp
00001 #include <Tsqr_TimeStats.hpp>
00002 #include <limits>
00003 
00006 
00007 namespace TSQR {
00008 
00009   TimeStats::TimeStats() { init(); }
00010 
00011   void
00012   TimeStats::init () {
00013     min_ = std::numeric_limits< double >::infinity();
00014     max_ = -std::numeric_limits< double >::infinity();
00015     mean_ = double (0);
00016     total_ = double (0);
00017     count_ = int (0);
00018   }
00019 
00020   void
00021   TimeStats::update (const double curTime) {
00022     total_ += curTime;
00023     count_++;
00024 
00025     if (curTime < min_)
00026       min_ = curTime;
00027     if (curTime > max_)
00028       max_ = curTime;
00029 
00030     // Mean(1:n) = ((n-1) / n) * Mean(1:n-1) + x(n) / n.
00031     //
00032     // Casting int to double is exact.
00033     const double scale = double(count_ - 1) / double(count_);
00034     mean_ = scale * mean_ + curTime / double(count_);
00035   }
00036 
00037   void
00038   TimeStats::print (std::ostream& out, 
00039         const bool humanReadable,
00040         const std::string& label,
00041         const std::string& labelLabel,
00042         const bool printHeaders) const
00043   {
00044     using std::endl;
00045 
00046     if (humanReadable)
00047       {
00048   const char prefix[] = "-- ";
00049   out << label << ":" << endl;
00050   if (count() == 0)
00051     out << prefix << "No values collected" << endl;
00052   else if (count() == 1)
00053     out << prefix << "One value collected: " << min() << endl;
00054   else
00055     {
00056       out << prefix << "Count: " << count() << endl
00057     << prefix << "Min:   " << min() << endl
00058     << prefix << "Mean:  " << mean() << endl
00059     << prefix << "Max:   " << max() << endl
00060     << prefix << "Total: " << total() << endl;
00061     }
00062       }
00063     else
00064       {
00065   // "%" identifies this line as a "comment" line to filter out.
00066   // First print field labels on one line, then print field
00067   // values on the next line.
00068   if (printHeaders)
00069     {
00070       out << "%" << labelLabel
00071     << "," << "count"
00072     << "," << "min"
00073     << "," << "mean"
00074     << "," << "max"
00075     << "," << "total" 
00076     << endl;
00077     }
00078   out << label
00079       << "," << count() 
00080       << "," << min() 
00081       << "," << mean()
00082       << "," << max()
00083       << "," << total()
00084       << endl;
00085       }
00086   }
00087 
00088 } // namespace TSQR
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends