1 // io_ex1.cpp ----------------------------------------------------------// 2 3 // Copyright 2010 Howard Hinnant 4 // Copyright 2010 Vicente J. Botet Escriba 5 // Copyright (c) Microsoft Corporation 2014 6 7 // Distributed under the Boost Software License, Version 1.0. 8 // See http://www.boost.org/LICENSE_1_0.txt 9 10 /* 11 This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation. 12 Many thanks to Howard for making his code available under the Boost license. 13 14 */ 15 16 #include <iostream> 17 #include <boost/chrono/config.hpp> 18 #include <boost/chrono/chrono_io.hpp> 19 #include <boost/chrono/system_clocks.hpp> 20 #include <boost/chrono/thread_clock.hpp> 21 #include <boost/chrono/process_cpu_clocks.hpp> 22 main()23int main() 24 { 25 using std::cout; 26 using namespace boost; 27 using namespace boost::chrono; 28 29 cout << "milliseconds(1) = " 30 << milliseconds(1) << '\n'; 31 cout << "milliseconds(3) + microseconds(10) = " 32 << milliseconds(3) + microseconds(10) << '\n'; 33 34 cout << "hours(3) + minutes(10) = " 35 << hours(3) + minutes(10) << '\n'; 36 37 typedef duration<long long, ratio<1, 2500000000ULL> > ClockTick; 38 cout << "ClockTick(3) + nanoseconds(10) = " 39 << ClockTick(3) + nanoseconds(10) << '\n'; 40 41 cout << "\nSet cout to use short names:\n"; 42 #if BOOST_CHRONO_VERSION==2 43 cout << duration_fmt(duration_style::symbol); 44 #else 45 cout << duration_short; 46 #endif 47 cout << "milliseconds(3) + microseconds(10) = " 48 << milliseconds(3) + microseconds(10) << '\n'; 49 50 cout << "hours(3) + minutes(10) = " 51 << hours(3) + minutes(10) << '\n'; 52 53 cout << "ClockTick(3) + nanoseconds(10) = " 54 << ClockTick(3) + nanoseconds(10) << '\n'; 55 56 cout << "\nsystem_clock::now() = " << system_clock::now() << '\n'; 57 #if defined _MSC_VER && _MSC_VER == 1700 58 #else 59 #if BOOST_CHRONO_VERSION==2 60 cout << "\nsystem_clock::now() = " << time_fmt(chrono::timezone::local) << system_clock::now() << '\n'; 61 cout << "\nsystem_clock::now() = " << time_fmt(chrono::timezone::local,"%Y/%m/%d") << system_clock::now() << '\n'; 62 #endif 63 #endif 64 65 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY 66 cout << "steady_clock::now() = " << steady_clock::now() << '\n'; 67 #endif 68 #if BOOST_CHRONO_VERSION==2 69 cout << "\nSet cout to use long names:\n" << duration_fmt(duration_style::prefix) 70 << "high_resolution_clock::now() = " << high_resolution_clock::now() << '\n'; 71 #else 72 cout << "\nSet cout to use long names:\n" << duration_long 73 << "high_resolution_clock::now() = " << high_resolution_clock::now() << '\n'; 74 #endif 75 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) 76 cout << "\nthread_clock::now() = " << thread_clock::now() << '\n'; 77 #endif 78 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) 79 cout << "\nprocess_real_cpu_clock::now() = " << process_real_cpu_clock::now() << '\n'; 80 #if BOOST_PLAT_WINDOWS_DESKTOP 81 cout << "\nprocess_user_cpu_clock::now() = " << process_user_cpu_clock::now() << '\n'; 82 cout << "\nprocess_system_cpu_clock::now() = " << process_system_cpu_clock::now() << '\n'; 83 cout << "\nprocess_cpu_clock::now() = " << process_cpu_clock::now() << '\n'; 84 #endif 85 #endif 86 return 0; 87 } 88