-
measure time complexity
Hello
I'd like to measure time complexity that its needed for some algorithm/function to complete in my c++ application. I'd like to have it in miliseconds, double format (example: 0.253ms)
I've tried doing the following:
Code:
#include <boost/date_time/posix_time/posix_time_types.hpp>
//..
boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
function();
boost::posix_time::time_duration time = boost::posix_time::microsec_clock::universal_time() - start;
std::cout << "done in: " << (double)(time.total_microseconds()/1000.0) << " ms\n";
But this will only output 0.
What am I doing wrong?
Is there any better way of doing this?
Thanks for help!
-
Have you considered that the microsecond precision in Boost may not actually reflect the TRUE precision of the system's clock timing?
Just becuse the time is specified in microseconds, doesn't meant that it's supplied with microsecond precision. Most OS's supply the current time in 1-10 ms chunks.
Try running your function 100 times or something like that...
Note also that you can do quite a lot of regular instructions in a microsecond - around 2000-4000 on a 2GHz processor - so unless your function is quite comples, it may well take less than a microsecond to complete.
--
Mats