I'm looking for a cross-platform clock with high resolution, high precision, and relatively low performance impact (in order of importance).
I've tried:
//using namespace std::chrono;
//typedef std::chrono::high_resolution_clock Clock;
using namespace boost::chrono;
typedef boost::chrono::high_resolution_clock Clock;
auto now = Clock::now().time_since_epoch();
std::size_t secs = duration_cast<seconds>(now).count();
std::size_t nanos = duration_cast<nanoseconds>(now).count() % 1000000000;
std::time_t tp = (std::time_t) secs;
std::string mode;
char timestamp[] = "yyyymmdd HH:MM:SS";
char format[] = "%Y%m%d %H:%M:%S";
strftime(timestamp, 80, format, std::localtime(&tp)); // Takes 12 microseconds
std::string output = timestamp + "." + std::to_string(nanos);
After some trials and testing: The original std::chrono::high_resolution_clock is typedef to system_clock and has precision of roughly 1 millisecond. The boost::chrono::high_resolution_clock uses the Query_Performance_Counter on Windows and has high resolution and precision. Unfortunately, Clock::now() returns time since boot and now().time_since_epoch() does not return epoch time (also returns time since boot).
Don't mind using guards for different solutions on different platforms (want VS2013 and Linux). Will likely store the now and do the processing in a separate/low priority thread.
Does a cross-platform, high-resolution, high-precision, performance-friendly timer exist?
Is boost::chrono::high_resolution_clock::now().time_since_epoch() working as intended? It does not give a time since the last epoch. It only gives a time since last boot. Is there a way to convert this now() into seconds since the epoch.