I wonder if is there any way to get only the time without printing out the units :
#include <boost/chrono.hpp>
#include <iostream>
boost::chrono::milliseconds sumGlobal;
int main() {
boost::chrono::high_resolution_clock::time_point t1 ;
boost::chrono::high_resolution_clock::time_point t2 ;
for (i=0;i<10;i++)
{
t1 = boost::chrono::high_resolution_clock::now();
f(); //to waste time
t2 = boost::chrono::high_resolution_clock::now();
sumGlobal += (boost::chrono::duration_cast<boost::chrono::milliseconds>(t2-t1));
}
std::cout << sumGlobal << "\n";
}
the Output is :
123 milliseconds
I'd like to get only
123
Any solutions ?
milliseconds
is a template instantiation of theduration
class template:The stream output operator
<<
is overloaded for theduration
class:Given the template parameters of your case, the provided version by default adds the unit "milliseconds" as text.
But the duration class has the method
count
that will return you the duration in the specified unit (in your case milliseconds) as the specified integer type (therep
type parameter, in your caseboost::int_least64_t
):You can output that integer number in your own format (in your case just the pure number):