Test boost::chrono::process_cpu_clock
This commit is contained in:
36
boost_chrono_process_cpu.cpp
Normal file
36
boost_chrono_process_cpu.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#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;
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user