io_ex3.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // io_ex1.cpp ----------------------------------------------------------//
  2. // Copyright 2010 Howard Hinnant
  3. // Copyright 2010 Vicente J. Botet Escriba
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. /*
  7. This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation.
  8. Many thanks to Howard for making his code available under the Boost license.
  9. */
  10. #include <boost/chrono/chrono_io.hpp>
  11. #include <sstream>
  12. #include <iostream>
  13. #include <boost/assert.hpp>
  14. int main()
  15. {
  16. using namespace boost::chrono;
  17. using std::cout;
  18. high_resolution_clock::time_point t0 = high_resolution_clock::now();
  19. std::stringstream io;
  20. io << t0;
  21. BOOST_ASSERT(!io.fail());
  22. cout << io.str() << '\n';
  23. BOOST_ASSERT(!io.fail());
  24. high_resolution_clock::time_point t1;
  25. io >> t1;
  26. BOOST_ASSERT(!io.fail());
  27. cout << io.str() << '\n';
  28. cout << t0 << '\n';
  29. cout << t1 << '\n';
  30. high_resolution_clock::time_point t = high_resolution_clock::now();
  31. cout << t << '\n';
  32. cout << "That took " << t - t0 << '\n';
  33. cout << "That took " << t - t1 << '\n';
  34. return 0;
  35. }
  36. //~ 50908679121461 nanoseconds since boot
  37. //~ That took 649630 nanoseconds