Page 1 of 1

About CPU time

Posted: Sat Apr 19, 2003 4:26 pm
by haaaz
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?

Posted: Sat Apr 19, 2003 7:22 pm
by kmhasan
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:

Code: Select all

time ./a.out < a.in
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]

Posted: Thu May 22, 2003 3:11 pm
by haaaz
How about memory usage?

Posted: Wed Jun 18, 2003 4:58 pm
by anupam
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?
---
:oops: :oops:

Posted: Fri Jun 20, 2003 6:44 pm
by ec3_limz
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?
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.

Posted: Sun Jun 22, 2003 2:15 pm
by anupam
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..