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