mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 04:22:55 +01:00
Use std::chrono for GetTimeMillis/GetTimeMicros
It's slightly faster then the boost variant as it has less overhead.
This commit is contained in:
parent
c678510677
commit
a3bc3fd0f0
@ -15,6 +15,8 @@
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
static std::atomic<int64_t> nMockTime(0); //!< For unit testing
|
||||
|
||||
int64_t GetTime()
|
||||
@ -39,16 +41,14 @@ int64_t GetMockTime()
|
||||
|
||||
int64_t GetTimeMillis()
|
||||
{
|
||||
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
|
||||
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_milliseconds();
|
||||
int64_t now = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
|
||||
assert(now > 0);
|
||||
return now;
|
||||
}
|
||||
|
||||
int64_t GetTimeMicros()
|
||||
{
|
||||
int64_t now = (boost::posix_time::microsec_clock::universal_time() -
|
||||
boost::posix_time::ptime(boost::gregorian::date(1970,1,1))).total_microseconds();
|
||||
int64_t now = std::chrono::time_point_cast<std::chrono::microseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
|
||||
assert(now > 0);
|
||||
return now;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user