Running time function in c

This is a discussion on Running time function in c within the C Programming forums, part of the General Programming Boards category; Hi ,I need to figure out the running time of a program ,is there any build in function in c(like ...

  1. #1
    lio
    lio is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    47

    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
    Thanks
    Last edited by lio; 01-21-2011 at 04:56 AM.

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    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.

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

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

    Code:
    #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, 09:56 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11: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 Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

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