cartographer时间相关知识点
1 #include 2 #include 3 #include 4 5 #include "cartographer/common/port.h" 6 7 namespace cartographer { 8 namespace common { 9 10 constexpr int64 kUtsEpochOffsetFromUnixEpochInSeconds =11 (719162ll * 24ll * 60ll * 60ll);//719162ll/365=1970.312 13 struct UniversalTimeScaleClock {14 using rep = int64;15 using period = std::ratio<1, 10000000>;//单位10ns16 using duration = std::chrono::duration;17 using time_point = std::chrono::time_point;18 static constexpr bool is_steady = true;19 };20 21 // Represents Universal Time Scale durations and timestamps which are 64-bit22 // integers representing the 100 nanosecond ticks since the Epoch which is23 // January 1, 1 at the start of day in UTC.24 using Duration = UniversalTimeScaleClock::duration;25 using Time = UniversalTimeScaleClock::time_point;26 27 // Convenience functions to create common::Durations.28 Duration FromSeconds(double seconds);29 Duration FromMilliseconds(int64 milliseconds);30 31 // Returns the given duration in seconds.32 double ToSeconds(Duration duration);33 double ToSeconds(std::chrono::steady_clock::duration duration);34 35 // Creates a time from a Universal Time Scale.36 Time FromUniversal(int64 ticks);37 38 // Outputs the Universal Time Scale timestamp for a given Time.39 int64 ToUniversal(Time time);40 41 // For logging and unit tests, outputs the timestamp integer.42 std::ostream& operator<<(std::ostream& os, Time time);43 44 // CPU time consumed by the thread so far, in seconds.45 double GetThreadCpuTimeSeconds();46 47 } // namespace common48 } // namespace cartographer
下面对上面的代码进行解释:
1、第一行的头文件#include
在C++11中,是标准模板库中与时间有关的头文件。该头文件中所有函数与类模板均定义在std::chrono命名空间中。
std::chrono::duration:记录时间长度,表示一段时间,如1分钟、2小时、10毫秒等。表示为类模板duration的对象,用一个count representation与一个period precision表示。例如,10毫秒的10为count representation,毫秒为period precision。
第一个模板参数为表示时间计数的数据类型。成员函数count返回该计数。第二个模板参数表示计数的一个周期,一般是std::ratio类型,表示一个周期(即一个时间滴答tick)是秒钟的倍数或分数,在编译时应为一个有理常量。
std::chrono::time_point:记录时间点的,表示一个具体的时间。例如某人的生日、今天的日出时间等。表示为类模板time_point的对象。用相对于一个固定时间点epoch的duration来表示。
std::chrono::clocks:时间点相对于真实物理时间的框架。至少提供了3个clock:
1)system_clock:当前系统范围(即对各进程都一致)的一个实时的日历时钟(Wallclock)。
2)steady_clock:当前系统实现的一个维定时钟,该时钟的每个时间滴答单位是均匀的(即长度相等)。
3)high_resolution_clock:当前系统实现的一个高分辨率时钟。
#include #include #include #include #include /////////////////////////////////////////////////////////////// // reference: int test_chrono_duration() {{ // duration::duration: Constructs a duration object // chrono::duration_cast: Converts the value of dtn into some other duration type, // taking into account differences in their periods typedef std::chrono::duration seconds_type; //template struct duration,前面是类型,后面是单位 typedef std::chrono::duration milliseconds_type;//typedef ratio<1, 1000> milli; typedef std::chrono::duration> hours_type; //template,分母默认值为1 hours_type h_oneday(24); // 24h seconds_type s_oneday(60 * 60 * 24); // 86400s milliseconds_type ms_oneday(s_oneday); // 86400000ms seconds_type s_onehour(60 * 60); // 3600s //hours_type h_onehour (s_onehour); // NOT VALID (type truncates), use: hours_type h_onehour(std::chrono::duration_cast(s_onehour)); milliseconds_type ms_onehour(s_onehour); // 3600000ms (ok, no type truncation) std::cout << ms_onehour.count() << "ms in 1h" << std::endl; } { // duration operators: +、-、*、/、>、<、!=、and so on std::chrono::duration foo; //默认单位都是秒 std::chrono::duration bar(10); // counts: foo bar // --- --- foo = bar; // 10 10 foo = foo + bar; // 20 10 ++foo; // 21 10 --bar; // 21 9 foo *= 2; // 42 9 foo /= 3; // 14 9 //bar += (foo % bar); // 14 14 std::cout << std::boolalpha; std::cout << "foo==bar: " << (foo == bar) << std::endl; std::cout << "foo: " << foo.count() << std::endl; std::cout << "bar: " << bar.count() << std::endl; } { // duration::count: Returns the internal count (i.e., the representation value) of the duration object. using namespace std::chrono; // std::chrono::milliseconds is an instatiation of std::chrono::duration: milliseconds foo(1000); // 1 second foo *= 60; std::cout << "duration (in periods): "; std::cout << foo.count() << " milliseconds.\n"; std::cout << "duration (in seconds): "; std::cout << foo.count() * milliseconds::period::num / milliseconds::period::den; std::cout << " seconds.\n"; } { // duration::max: Returns the maximum value of duration // duration::min: Returns the minimum value of duration std::cout << "system_clock durations can represent:\n"; std::cout << "min: " << std::chrono::system_clock::duration::min().count() << "\n"; std::cout << "max: " << std::chrono::system_clock::duration::max().count() << "\n"; } { // duration::zero: Returns a duration value of zero using std::chrono::steady_clock; steady_clock::time_point t1 = steady_clock::now(); std::cout << "Printing out something...\n"; steady_clock::time_point t2 = steady_clock::now(); steady_clock::duration d = t2 - t1; if (d == steady_clock::duration::zero()) std::cout << "The internal clock did not tick.\n"; else std::cout << "The internal clock advanced " << d.count() << " periods.\n"; } { // chrono::time_point_cast: Converts the value of tp into a time_point type with a different duration internal object, // taking into account differences in their durations's periods. using namespace std::chrono; typedef duration> days_type; time_point today = time_point_cast(system_clock::now()); std::cout << today.time_since_epoch().count() << " days since epoch" << std::endl; } return 0; } ////////////////////////////////////////////////////////////////// // reference: int test_chrono_high_resolution_clock() { // high_resolution_clock::now: Returns the current time_point in the frame of the high_resolution_clock using namespace std::chrono; high_resolution_clock::time_point t1 = high_resolution_clock::now(); std::cout << "printing out 1000 stars...\n"; for (int i = 0; i<1000; ++i) std::cout << "*"; std::cout << std::endl; high_resolution_clock::time_point t2 = high_resolution_clock::now(); duration time_span = duration_cast>(t2 - t1); std::cout << "It took me " << time_span.count() << " seconds."; std::cout << std::endl; return 0; } /////////////////////////////////////////////////////////////////////// // reference: int test_chrono_steady_clock() { // steady_clock is specifically designed to calculate time intervals. // steady_clock::now: Returns the current time_point in the frame of the steady_clock. using namespace std::chrono; steady_clock::time_point t1 = steady_clock::now(); std::cout << "printing out 1000 stars...\n"; for (int i = 0; i<1000; ++i) std::cout << "*"; std::cout << std::endl; steady_clock::time_point t2 = steady_clock::now(); duration time_span = duration_cast>(t2 - t1); std::cout << "It took me " << time_span.count() << " seconds."; std::cout << std::endl; return 0; } ////////////////////////////////////////////////////////////// // reference: int test_chrono_system_clock() { // system_clock is a system-wide realtime clock. { // system_clock::from_time_t: Converts t into its equivalent of member type time_point. using namespace std::chrono; // create tm with 1/1/2000: std::tm timeinfo = std::tm(); timeinfo.tm_year = 100; // year: 2000 timeinfo.tm_mon = 0; // month: january timeinfo.tm_mday = 1; // day: 1st std::time_t tt = std::mktime(&timeinfo); system_clock::time_point tp = system_clock::from_time_t(tt); system_clock::duration d = system_clock::now() - tp; // convert to number of days: typedef duration> days_type; days_type ndays = duration_cast (d); // display result: std::cout << ndays.count() << " days have passed since 1/1/2000"; std::cout << std::endl; } { // system_clock::now: Returns the current time_point in the frame of the system_clock using namespace std::chrono; duration > one_day(1); system_clock::time_point today = system_clock::now(); system_clock::time_point tomorrow = today + one_day; time_t tt; tt = system_clock::to_time_t(today); std::cout << "today is: " << ctime(&tt); tt = system_clock::to_time_t(tomorrow); std::cout << "tomorrow will be: " << ctime(&tt); } { // system_clock::to_time_t: Converts tp into its equivalent of type time_t. using namespace std::chrono; duration > one_day(1); system_clock::time_point today = system_clock::now(); system_clock::time_point tomorrow = today + one_day; time_t tt; tt = system_clock::to_time_t(today); std::cout << "today is: " << ctime(&tt); tt = system_clock::to_time_t(tomorrow); std::cout << "tomorrow will be: " << ctime(&tt); } return 0; } ////////////////////////////////////////////////////// // reference: int test_chrono_time_point() { { // time_point operators: +、-、==、!= using namespace std::chrono; system_clock::time_point tp, tp2; // epoch value system_clock::duration dtn(duration(1)); // 1 second // tp tp2 dtn // --- --- --- tp += dtn; // e+1s e 1s tp2 -= dtn; // e+1s e-1s 1s tp2 = tp + dtn; // e+1s e+2s 1s tp = dtn + tp2; // e+3s e+2s 1s tp2 = tp2 - dtn; // e+3s e+1s 1s dtn = tp - tp2; // e+3s e+1s 2s std::cout << std::boolalpha; std::cout << "tp == tp2: " << (tp == tp2) << std::endl; std::cout << "tp > tp2: " << (tp>tp2) << std::endl; std::cout << "dtn: " << dtn.count() << std::endl; } { // time_point::time_point: Constructs a time_point object using namespace std::chrono; system_clock::time_point tp_epoch; // epoch value time_point > tp_seconds(duration(1)); system_clock::time_point tp(tp_seconds); std::cout << "1 second since system_clock epoch = "; std::cout << tp.time_since_epoch().count(); std::cout << " system_clock periods." << std::endl; // display time_point: std::time_t tt = system_clock::to_time_t(tp); std::cout << "time_point tp is: " << ctime(&tt); } { // time_point::time_since_epoch: Returns a duration object with the time span value between the epoch and the time point using namespace std::chrono; system_clock::time_point tp = system_clock::now(); system_clock::duration dtn = tp.time_since_epoch(); std::cout << "current time since epoch, expressed in:" << std::endl; std::cout << "periods: " << dtn.count() << std::endl; std::cout << "seconds: " << dtn.count() * system_clock::period::num / system_clock::period::den; std::cout << std::endl; } return 0; } /////////////////////////////////////////////////////////////////// // reference: static long fibonacci(unsigned n) { if (n < 2) return n; return fibonacci(n - 1) + fibonacci(n - 2); } int test_chrono_1() { { // std::chrono::time_point std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); std::time_t now_c = std::chrono::system_clock::to_time_t(now - std::chrono::hours(24)); std::cout << "24 hours ago, the time was " << now_c << '\n'; std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); std::cout << "Hello World\n"; std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); std::cout << "Printing took " << std::chrono::duration_cast(end - start).count() << "us.\n"; } { // std::chrono::duration using shakes = std::chrono::duration>; using jiffies = std::chrono::duration; using microfortnights = std::chrono::duration>; using nanocenturies = std::chrono::duration>; std::chrono::seconds sec(1); std::cout << "1 second is:\n"; std::cout << std::chrono::duration_cast(sec).count() << " shakes\n"; std::cout << std::chrono::duration_cast(sec).count() << " jiffies\n"; std::cout << microfortnights(sec).count() << " microfortnights\n"; std::cout << nanocenturies(sec).count() << " nanocenturies\n"; } { // std::chrono::time_point start, end; start = std::chrono::system_clock::now(); std::cout << "f(42) = " << fibonacci(42) << '\n'; end = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = end - start; std::time_t end_time = std::chrono::system_clock::to_time_t(end); std::cout << "finished computation at " << std::ctime(&end_time) << "elapsed time: " << elapsed_seconds.count() << "s\n"; } return 0; } int main(int argc, char** argv){test_chrono_duration();return 0;}
View Code
看一下时间点,参考其他博客,再次写一下chrono相关的知识
chrono是一个time library, 源于boost,现在已经是C++标准。话说今年似乎又要出新标准了,好期待啊!
duration、time_point、clock
1)、
Durations
std::chrono::duration 表示一段时间,比如两个小时,12.88秒,半个时辰,一炷香的时间等等,只要能换算成秒即可。
template > class
其中
Rep表示一种数值类型,用来表示Period的数量,比如int float double
Period是ratio类型,用来表示【用秒表示的时间单位】比如second milisecond
常用的duration已经定义好了,在std::chrono::duration下:
ratio<3600, 1> hours
ratio<60, 1> minutes
ratio<1, 1> seconds
ratio<1, 1000> microseconds
ratio<1, 1000000> microseconds
ratio<1, 1000000000> nanosecons
这里需要说明一下ratio这个类模版的原型:
template class
N代表分子,D代表分母,所以ratio表示一个分数值。
注意,我们自己可以定义Period,比如ratio<1, -2>表示单位时间是-0.5秒。
由于各种duration表示不同,chrono库提供了duration_cast类型转换函数。
1 template 2 constexpr ToDuration duration_cast (const
典型用法:
// duration constructor#include #include #include int main (){ typedef std::chrono::duration seconds_type; typedef std::chrono::duration milliseconds_type; typedef std::chrono::duration> hours_type; hours_type h_oneday (24); // 24h seconds_type s_oneday (60*60*24); // 86400s milliseconds_type ms_oneday (s_oneday); // 86400000ms seconds_type s_onehour (60*60); // 3600s//hours_type h_onehour (s_onehour); // NOT VALID (type truncates), use: hours_type h_onehour (std::chrono::duration_cast(s_onehour)); milliseconds_type ms_onehour (s_onehour); // 3600000ms (ok, no type truncation) std::cout << ms_onehour.count() << "ms in 1h" << std::endl; return 0;}duration还有一个成员函数count()返回Rep类型的Period数量,看代码:// duration::count#include // std::cout#include // std::chrono::seconds, std::chrono::milliseconds // std::chrono::duration_castint main (){ using namespace std::chrono; // std::chrono::milliseconds is an instatiation of std::chrono::duration: milliseconds foo (1000); // 1 second foo*=60; std::cout << "duration (in periods): "; std::cout << foo.count() << " milliseconds.\n"; std::cout << "duration (in seconds): "; std::cout << foo.count() * milliseconds::period::num / milliseconds::period::den; std::cout << " seconds.\n"; return 0;}
View Code
2)Time points
std::chrono::time_point表示一个具体时间,如上个世纪80年代、你的生日、今天下午、火车出发时间等,只要它能用计算机时钟表示。鉴于我们使用时间的情景不同,这个time point具体到什么程度,由选用的单位决定。一个time point必须有一个clock计时。
template class
下面是构造使用time_point的例子
// time_point constructors#include #include #include int main (){ using namespace std::chrono; system_clock::time_point tp_epoch; // epoch value time_point > tp_seconds (duration(1)); system_clock::time_point tp (tp_seconds); std::cout << "1 second since system_clock epoch = "; std::cout << tp.time_since_epoch().count(); std::cout << " system_clock periods." << std::endl; // display time_point: std::time_t tt = system_clock::to_time_t(tp); std::cout << "time_point tp is: " << ctime(&tt); return 0;}
View Code
time_point有一个函数time_from_eproch()用来获得1970年1月1日到time_point时间经过的duration。
举个例子,如果timepoint以天为单位,函数返回的duration就以天为单位。
由于各种time_point表示方式不同,chrono也提供了相应的转换函数 time_point_cast。
1 template 2 time_point time_point_cast (const
/ time_point_cast#include #include #include int main (){ using namespace std::chrono; typedef duration> days_type; time_point today = time_point_cast(system_clock::now()); std::cout << today.time_since_epoch().count() << " days since epoch" << std::endl; return 0;}
View Code
3)clocks
std::chrono::system_clock 它表示当前的系统时钟,系统中运行的所有进程使用now()得到的时间是一致的。
每一个clock类中都有确定的time_point, duration, Rep, Period类型。
操作有:
now() 当前时间time_point
to_time_t() time_point转换成time_t秒
from_time_t() 从time_t转换成time_point
典型的应用是计算时间日期:
// system_clock example#include #include #include #include int main (){ using std::chrono::system_clock; std::chrono::duration > one_day (1); system_clock::time_point today = system_clock::now(); system_clock::time_point tomorrow = today + one_day; std::time_t tt; tt = system_clock::to_time_t ( today ); std::cout << "today is: " << ctime(&tt); tt = system_clock::to_time_t ( tomorrow ); std::cout << "tomorrow will be: " << ctime(&tt); return 0;}
View Code
std::chrono::steady_clock 为了表示稳定的时间间隔,后一次调用now()得到的时间总是比前一次的值大(这句话的意思其实是,如果中途修改了系统时间,也不影响now()的结果),每次tick都保证过了稳定的时间间隔。
操作有:
now() 获取当前时钟
典型的应用是给算法计时:
// steady_clock example#include #include #include #include int main (){ using namespace std::chrono; steady_clock::time_point t1 = steady_clock::now(); std::cout << "printing out 1000 stars...\n"; for (int i=0; i<1000; ++i) std::cout << "*"; std::cout << std::endl; steady_clock::time_point t2 = steady_clock::now(); duration time_span = duration_cast>(t2 - t1); std::cout << "It took me " << time_span.count() << " seconds."; std::cout << std::endl; return 0;}
View Code
最后一个时钟,std::chrono::high_resolution_clock 顾名思义,这是系统可用的最高精度的时钟。实际上high_resolution_clock只不过是system_clock或者steady_clock的typedef。
2、第三行#include
其是在c++11中引入的,模板类std::ratio以及相关的模板类(如std::ratio_add)提供编译时有理数算术支持。
此模板的每个实例化都准确表示任意有限有理数。他们都是用来表示比例关系的模板类。
template class
其中N表示分子,D表示分母;intmax_t表示最大的有符号整数类型,N和D的绝对值都应该在intmax_t可表示的范围内,D不能为0.
std::ratio类一般不通过它的对象来表示,而是这个类型本身来表示的,但也可以通过它的对象来表示。std::ratio有两个成员常量:num表示的是分子,den表示的是分母。这里的num和den已经经过化简,因此输出值可能和定义时传入的不同,如typedef std::ratio<100, 10> ratio1, 输出值ratio1::num为10,ratio1::den为1,求其最大公约数。
在include中,除std::ratio外,还有编译时有理数算术:std::ratio_add、std::ratio_subtract、std::ratio_multiply、std::ratio_divide,它们和std::ratio一样,也都有两个成员常量:num和den。编译时有理数比较:std::ratio_equal、std::ratio_not_equal、std::ratio_less、std::ratio_less_equal、std::ratio_greater、std::ratio_greater_equal,它们都有value成员常量。它们的计算公式如下:
template using ratio_add = ratio < R1::num*R2::den+R2::num*R1::den, R1::den*R2::den > template using ratio_subtract = std::ratio < R1::num*R2::den-R2::num*R1::den, R1::den*R2::den > template using ratio_multiply = std::ratio < R1::num * R2::num, R1::den * R2::den >; template using ratio_divide = ratio < R1::num * R2::den, R2::num * R1::den >; template struct ratio_equal : integral_constant {} template struct ratio_less : integral_constant < bool, R1::num*R2::den < R2::num*R1::den > {}; template struct ratio_greater : integral_constant < bool, ratio_less::value > {}; template struct ratio_greater_equal : integral_constant < bool, !ratio_less::value > {}; template struct ratio_less_equal : integral_constant < bool, !ratio_less::value > {} template struct ratio_equal : integral_constant < bool, !ratio_equal::value > {};
View Code
#include "ratio.hpp"#include #include //// reference: test_ratio_1(){ typedef std::ratio<1, 3> one_third; typedef std::ratio<2, 4> two_fourths; typedef std::ratio<2, 3> two_thirds; typedef std::ratio<1, 2> one_half; std::cout << "one_third= " << one_third::num << "/" << one_third::den << std::endl; std::cout << "two_fourths= " << two_fourths::num << "/" << two_fourths::den << std::endl; // Note: 1/2 std::cout << "two_thirds= " << two_thirds::num << "/" << two_thirds::den << std::endl; std::cout << "one_half= " << one_half::num << "/" << one_half::den << std::endl; std::cout << std::endl; { // std::ratio typedef std::ratio_add sum; std::cout << "sum= " << sum::num << "/" << sum::den; std::cout << " (which is: " << (double(sum::num) / sum::den) << ")" << std::endl; std::cout << "1 kilogram has " << (std::kilo::num / std::kilo::den) << " grams"; std::cout << std::endl;} { // std::ratio_add typedef std::ratio_add sum; std::cout << "sum = " << sum::num << "/" << sum::den; std::cout << " (which is: " << (double(sum::num) / sum::den) << ")" << std::endl;} { // std::ratio_subtract typedef std::ratio_subtract diff; std::cout << "diff = " << diff::num << "/" << diff::den; std::cout << " (which is: " << (double(diff::num) / diff::den) << ")" << std::endl;} { // std::ratio_multiply typedef std::ratio_multiply result; std::cout << "result = " << result::num << "/" << result::den; std::cout << " (which is: " << (double(result::num) / result::den) << ")" << std::endl;} { // std::ratio_divide typedef std::ratio_divide result; std::cout << "result = " << result::num << "/" << result::den; std::cout << " (which is: " << (double(result::num) / result::den) << ")" << std::endl; std::cout << std::endl;} { // std::ratio_equal std::cout << "1/2 == 2/4 ? " << std::boolalpha; std::cout << std::ratio_equal::value << std::endl;} { // std::ratio_greater std::cout << "1/3 > 1/2 ? " << std::boolalpha; std::cout << std::ratio_greater::value << std::endl;} { // std::ratio_greater_equal std::cout << "1/3 >= 1/2 ? " << std::boolalpha; std::cout << std::ratio_greater_equal::value << std::endl;} { // std::ratio_less std::cout << "1/3 < 1/2 ? " << std::boolalpha; std::cout << std::ratio_less::value << std::endl;} { // std::ratio_less_equal std::cout << "1/3 <= 1/2 ? " << std::boolalpha; std::cout << std::ratio_less_equal::value << std::endl;} { // std::ratio_not_equal std::cout << "1/2 != 2/4 ? " << std::boolalpha; std::cout << std::ratio_not_equal::value << std::endl;} std::cout << std::endl; return 0;} /// reference: test_ratio_2(){ // If you don't use a typedef you're creating an instance of std::ratio<1, 3> named one_third, // which is not suitable for passing as a type argument.In that case you'll need to use decltype // to get to the appropriate type that can be passed to ratio_add std::ratio<1, 3> one_third; std::ratio<2, 4> two_fourths; std::ratio_add sum; std::cout << decltype(sum)::den << std::endl; return 0;}
View Code
std::ratio 定义分式
60, 1> minutes;//<分子,分母>一分钟60秒 std::ratio<60 * 60> hource;//1小时3600秒 std::ratio<1, 1000> milliseconds; //1ms是1/1000秒
chrono命名空间定义好的时间单位
typedef duration > hours; typedef duration > minutes; typedef duration > seconds; typedef duration > milliseconds; typedef duration > microseconds; typedef duration > nanoseconds;
举例
chrono::minutes mintu{2};//2分钟 chrono::seconds sec{3};//3秒钟 chrono::milliseconds mills{500};//500毫秒 auto dul = sec - mills;//两者差值,单位默认转到更小的 2500ms dul.count(); //值为2500 std::this_thread::sleep_for(std::chrono::milliseconds(100)); //当前线程休眠100毫秒
time.cc
#include "cartographer/common/time.h"#include #include #include #include #include "glog/logging.h"namespace cartographer {namespace common {Duration FromSeconds(const double seconds) { return std::chrono::duration_cast( std::chrono::duration(seconds));}double ToSeconds(const Duration duration) { return std::chrono::duration_cast>(duration) .count();}double ToSeconds(const std::chrono::steady_clock::duration duration) { return std::chrono::duration_cast>(duration) .count();}Time FromUniversal(const int64 ticks) { //using duration = std::chrono::duration; // using time_point = std::chrono::time_point; printf("ticks is %ld ", ticks);//add by gary printf("Duration'count is %lf ",Duration(ticks).count()); printf("Time is %lf\n",Time(Duration(ticks)).time_since_epoch().count()); return Time(Duration(ticks));}int64 ToUniversal(const Time time) { return time.time_since_epoch().count(); }std::ostream& operator<<(std::ostream& os, const Time time) { os << std::to_string(ToUniversal(time)); return os;}common::Duration FromMilliseconds(const int64 milliseconds) { return std::chrono::duration_cast( std::chrono::milliseconds(milliseconds));}double GetThreadCpuTimeSeconds() {#ifndef WIN32 struct timespec thread_cpu_time; CHECK(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &thread_cpu_time) == 0) << std::strerror(errno); return thread_cpu_time.tv_sec + 1e-9 * thread_cpu_time.tv_nsec;#else return 0.;#endif}} // namespace common} // namespace cartographer
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~