How to calculate compile-time in C++
Results 1 to 5 of 5

Thread: How to calculate compile-time in C++

  1. #1
    Member
    Join Date
    Feb 2002
    Posts
    34

    How to calculate compile-time in C++

    Hi buddies,
    Would you please help me out.
    I know this way:

    int start_time, end_time
    start_time=time(0);
    (main program is here)
    end_time=time(0);
    int cputime;
    cputime=end_time - start_time;

    But with this method, I can only get the comile-time in seconds. As a result, most of the trials, I got the cputime = 0 second. And, what I'd like to do is to calculate the compile-time in millisecond (or something smaller than second).

    Thanks in advance for your precious help
    ILCF

  2. #2
    Junior Member
    Join Date
    Jan 2003
    Posts
    2

    Windows timing function

    In windows you can use the function called timeGetTime.

    Code:
    #include <winpocs.h>
    
    /* Place this in the WinMain function: */
    
    int start_time, end_time
    start_time=timeGetTime();
    (main program is here)
    end_time=timeGetTime();
    int cputime;
    cputime=end_time - start_time;
    I don't know any *nix function for this... sorry

  3. #3
    Senior Member
    Join Date
    Jul 2001
    Posts
    420
    For Unix you might want to try times.

    #include <sys/times.h>
    #include <limits.h>

    //theres also :

    int getrusage (int who, struct rusage *rusage);

    the above is from Unix Systems Programming for SVR4 published by O'Reilly (http://ora.com)

    Hope that help.

    If your doing Unix system programing I found that text very useful.
    If you spend more on coffee than on IT security, you will be hacked. What\'s more, you deserve to be hacked.
    -- former White House cybersecurity adviser Richard Clarke

  4. #4
    Senior Member
    Join Date
    Sep 2001
    Posts
    1,027
    This is an old thread and I don't want to fuel it pointlessly, but this has to be said:
    Doing this WILL NOT GIVE YOU THE COMPILATION DURATION; these are runtime calls, they will only give you the time elapsed between the start of execution of the program and the end of execution.

    To have the compilation duration, in unix you could use a command like
    > time CC your_program

    in windows you might be able to do the same thing (not sure if the "time" utility is there by default or if it's in the resource kit...) if you compile at the commande line...
    If you compile with an IDE, well check your IDE's options...


    Ammo
    Credit travels up, blame travels down -- The Boss

  5. #5
    The Iceman Cometh
    Join Date
    Aug 2001
    Posts
    1,210
    I know there's another function call in UNIX (or Windows, for that matter) which you can use if you are trying to find the run-time of a program, procedure, function, etc. I can't recall, off-hand, what it is though. I'll look it up, though. One thing you can try is to simply declare the times as floats, rather than integers. I'm not sure what the time(0) function returns, but if it returns a float, it'll work. Also, ammo made a very good point... what you are essentially doing is getting the run-time, not the compile-time. Compile time, as he said, would be calculated when you compile it, while the commands you use are only executed when the program is run (therefore, calculating only run-time). Anyway, if you're still having the problem, good luck.

    AJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •