Thread: clock() - perfomance measurement

  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,229
    try gettimeofday() in sys/time.h

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    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
    39,660
    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.

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, 12: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, 05:15 AM
  4. clock program
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 10:12 PM
  5. time measurement using clock() and time()
    By kuhnmi in forum C++ Programming
    Replies: 1
    Last Post: 08-13-2004, 06:32 AM