标签:poi pos std min class end ace time div
//关于duration: #include <iostream> #include <chrono> using namespace std; using namespace std::chrono; void f(int x) { for(int i=0;i!=x;++i) cout << i << ‘ ‘; cout << endl; } int main() { auto t1 = system_clock::now(); f(10); // do something auto t2 = system_clock::now(); auto dms = duration_cast<milliseconds>(t2-t1); cout << "f(x) took " << dms.count() << " milliseconds\n"; auto ds = duration_cast<seconds>(t2-t1); cout << "f(x) took " << ds.count() << " seconds\n"; return 0; } -------------------------------------------------------------------------------------------- //关于time_point: #include <iostream> #include <chrono> using namespace std; using namespace std::chrono; int main() { auto tp = steady_clock::now(); auto d1 = time_point_cast<hours>(tp).time_since_epoch().count()/24; //从纪元开始到现在的天数 using days=duration<long,ratio<24*60*60,1>>; auto d2 = time_point_cast<days>(tp).time_since_epoch().count(); if(d1!=d2) cout << "Impossible!\n"; return 0; } ----------------------------------------------------------------------------------------------- //关于clock: #include <iostream> #include <chrono> using namespace std; using namespace std::chrono; int main() { cout << "min " << system_clock::duration::min().count() << ", max " << system_clock::duration::max().count() << ", " << (treat_as_floating_point<system_clock::duration>::value?"FP":"integral") << ‘\n‘; cout << (system_clock::is_steady?"steady\n":"not steady\n"); return 0; }
标签:poi pos std min class end ace time div
原文地址:https://www.cnblogs.com/lhb666aboluo/p/13335279.html