How can I know how long my program runs?
Do I have to code myself or I can get such information from my compiler.......?
And how about the memory size a program uses?
About CPU time
Moderator: Board moderators
If you're using linux it's trivial, you don't need to do add anything in the code. Given a binary executable a.out and an input file a.in you can use:
For platform independence, I think you can use the functions provided in time.h.
[cpp]
#include <time.h>
#include <stdio.h>
int main() {
clock_t start = clock();
/* do whatever is needed */
clock_t stop = clock();
printf("%.3lfs\n",(double)(stop-start)/CLOCKS_PER_SEC);
return 0;
}
[/cpp]
Code: Select all
time ./a.out < a.in
[cpp]
#include <time.h>
#include <stdio.h>
int main() {
clock_t start = clock();
/* do whatever is needed */
clock_t stop = clock();
printf("%.3lfs\n",(double)(stop-start)/CLOCKS_PER_SEC);
return 0;
}
[/cpp]
K M Hasan
http://www.cs.umanitoba.ca/~kmhasan/
http://www.cs.umanitoba.ca/~kmhasan/
I think the functions in time.h are available for any compiler. However, I don't see any point in sending a program using the time functions to the judge.well problemsetter bhai, thanks for your great teaching.
it's very important use.
will it work on cygwin?
will there be any problem to judge if i use clock_t will it return compile error?
well a great important question is abt memory usage.
this is bcz it is not possible to calculate total memory from all the variable list whn using a big program.
and many dos compiler don't allow a fixed limit of memory.
so how many variables to allocate in the given menmory is a big ?.
--
if any1 knows please let us know abt it..
this is bcz it is not possible to calculate total memory from all the variable list whn using a big program.
and many dos compiler don't allow a fixed limit of memory.
so how many variables to allocate in the given menmory is a big ?.
--
if any1 knows please let us know abt it..
"Everything should be made simple, but not always simpler"