Thread: measure time complexity

  1. #1
    Registered User
    Join Date
    May 2006

    measure time complexity


    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:

    #include <boost/date_time/posix_time/posix_time_types.hpp>
    boost::posix_time::ptime start = boost::posix_time::microsec_clock::universal_time();
    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!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    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.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time measure (net and gross) with pthreads under linux
    By mynickmynick in forum Linux Programming
    Replies: 12
    Last Post: 12-01-2008, 07:39 AM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM