clock() - perfomance measurement

This is a discussion on clock() - perfomance measurement within the C++ Programming forums, part of the General Programming Boards category; Is the clock() function efective for micro-benchmarks? Or there is another another that is more precise? Thabk you....

  1. #1
    Registered User
    Join Date
    Oct 2005
    Location
    Brasil
    Posts
    220

    clock() - perfomance measurement

    Is the clock() function efective for micro-benchmarks? Or there is another another that is more precise?

    Thabk you.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    try gettimeofday() in sys/time.h

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Scarvenger View Post
    Is the clock() function efective for micro-benchmarks? Or there is another another that is more precise?
    Depends what you mean by micro-benchmark. On a non-real-time system you always have a random background latency which makes very small time measurements meaningless. If you can repeat the operation you are trying to measure, the best thing to do is to perform it several thousands or millions of times and find the average time. You can then subtract the average latency, assuming you can measure that.

    A lot of systems have a profile timer that increments only while in user code, which makes the measurements a bit more accurate but still probably not accurate enough for events of a microsecond or shorter.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,833
    A recent thread...
    Timing basic operations in C++
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 01:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 06:15 PM
  3. Clock Troubles
    By _Nate_ in forum C Programming
    Replies: 22
    Last Post: 06-19-2008, 06:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 11:12 PM
  5. time measurement using clock() and time()
    By kuhnmi in forum C++ Programming
    Replies: 1
    Last Post: 08-13-2004, 07:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21