-
December 23rd, 2002, 09:03 AM
#1
Member
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
-
January 15th, 2003, 10:46 PM
#2
Junior Member
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
-
January 15th, 2003, 11:40 PM
#3
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
-
January 16th, 2003, 01:55 AM
#4
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
-
January 16th, 2003, 04:39 AM
#5
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
-
Forum Rules
|
|