io_ex1.cpp 3.1 KB

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