Thread: Running time function in c

  1. #1
    Registered User
    Join Date
    Nov 2010

    Running time function in c

    Hi ,I need to figure out the running time of a program ,is there any build in function in c(like System.currentTimeMillis() in JAVA),or I have to write one
    Last edited by lio; 01-21-2011 at 04:56 AM.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    There is no inbuilt function apart from the time library to use. If you want to profile your code there are library avaliable out there. Check you compiler documenation or if your gcc you could use gprof.

    Life is like riding a bicycle. To keep your balance you must keep moving - Einstein

  3. #3
    Registered User
    Join Date
    Jan 2011
    I think this may help you out. This gives the the approximate time (more than the observed running time by "time" command in linux).

    #include <stdio.h>
    #include <time.h>
    int main()
            int time1, time2;
            time1 = clock();                                      //Initial Observation
            Your code
            time2 = clock();                              //Final observation
            printf ("Time Elapsed = %f\n", (float)(time2 - time1) / (float)CLOCKS_PER_SEC);
            return 0;
    Thanks and Best Regards,
    Aakash Johari

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Replies: 4
    Last Post: 11-23-2003, 07:15 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM