I would like to have a function to get time since epoch in ns. I was having a solution using boost::ptime
:
auto cur_time = ptime(day_clock::universal_day(), return microsec_clock::universal_time().time_of_day());
return (cur_time - date(1970,1,1)).total_microseconds();
I also tested the solution using std::chrono:
return std::chrono::duration_cast< std::chrono::microseconds >(std::chrono::system_clock::now().time_since_epoch()).count();
The boost solution is 10 times slower than the std::chrono solution. (150ns vs 1500ns on my Linux machine). Is there a better(faster) way to get the time since epoch in Boost::datetime that I am missing?