time a process

This is a discussion on time a process within the C Programming forums, part of the General Programming Boards category; Hi, I am looking for a way to time how long the execution of a function in my code takes. ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    59

    time a process

    Hi,

    I am looking for a way to time how long the execution of a function in my code takes. What is the easiest way to do this. I was told to look at time.h but I cannot find a way to count seconds and I am having some difficulty.

    I am not looking for code but simply some suggestions.

    Thanks in advance,

    Chris
    " . . . and I lay awake, big dreamers never sleep." - David Lee Roth

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    175
    why don't you look for clock function.

    BTW, what OS and what compiler are you using?

  3. #3
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    You could use the standard function clock().

    #include <time.h>
    clock_t clock(void);

    Call clock() before the operation and clock() after the operation. Calculate the difference, divide it by CLOCKS_PER_SEC and you should get the difference in seconds.

  4. #4
    VanJay001379
    Guest
    Originally posted by Roaring_Tiger
    why don't you look for clock function.

    BTW, what OS and what compiler are you using?
    I'm using Unix and the Workshop compiler.

    Will the clock return the time in milliseconds or seconds?

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    59
    Are the units returned platform dependant? What are they?

    Also, will the clock function operate on Windows as well as UNIX?
    Last edited by VanJay011379; 02-11-2003 at 11:32 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When does a process not consume time
    By chasek92009 in forum C Programming
    Replies: 2
    Last Post: 10-21-2007, 07:34 PM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. time synchronization problem
    By freeindy in forum C Programming
    Replies: 1
    Last Post: 04-19-2007, 06:25 AM
  4. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

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