Measuring execution time

Oct 30, 2009 at 8:57pm
I need to measure the execution time of my programs...
any one knows an easy way to do that in C?
Oct 30, 2009 at 9:18pm
http://www.cplusplus.com/reference/clibrary/ctime/clock/

Note: clock() behaves slightly differently across platforms, even after factoring in CLOCKS_PER_SEC.
Oct 30, 2009 at 9:45pm
what do you mean with "behaves differently"?
im using ubuntu...
this is a problem that i have to worrie about?
Oct 30, 2009 at 9:56pm
For example:
1
2
3
4
int a;
unsigned t0=clock(),t1;
std::cin >>a;
t1=clock()-t0;

On Linux, t1 will always equal zero. clock() returns how much processor time the process has used since it started.
On Windows, the value of t1 depends on how long the user took to enter something. clock() returns how how much time has passed since the process started.

EDIT: Furthermore, I have not idea how clock() behaves in multithreaded applications.
Last edited on Oct 30, 2009 at 9:59pm
Oct 30, 2009 at 10:07pm
uhn...
i think i got the difference
but i need to get the execution time of the program, like the "time" command in linux...
there is a way of doing it?
Oct 30, 2009 at 10:46pm
You have already been given the answer twice -- the second time with a working example. If you want more information, read the manual:
http://linux.die.net/man/7/time

And/or google around "c/c++ profiling".

Good luck.
Oct 30, 2009 at 11:11pm
thx
Topic archived. No new replies allowed.