Files
test/cpp/boost_chrono_process_cpu.cpp

37 lines
843 B
C++

#include <iostream>
#include <exception>
#include <string>
#include <chrono>
#include <thread>
#include <boost/chrono/process_cpu_clocks.hpp>
int main ( void )
{try{
boost::chrono::process_cpu_clock clock;
boost::chrono::process_cpu_clock::time_point b = clock.now();
std::this_thread::sleep_for( std::chrono::seconds( 2 ) );
boost::chrono::process_cpu_clock::time_point e = clock.now();
boost::chrono::process_cpu_clock::duration d = e - b;
auto times = d.count();
std::cout << times.real / 1e+9 << std::endl;
std::cout << times.user / 1e+9 << std::endl;
std::cout << times.system / 1e+9 << std::endl;
return 0;
}
catch ( const std::exception& e )
{
std::cerr << std::endl
<< "std::exception(\"" << e.what() << "\")." << std::endl;
}
catch ( ... )
{
std::cerr << std::endl
<< "unknown exception." << std::endl;
}}