Measuring execution time

I need to measure the execution time of my programs...
any one knows an easy way to do that in C?
http://www.cplusplus.com/reference/clibrary/ctime/clock/

Note: clock() behaves slightly differently across platforms, even after factoring in CLOCKS_PER_SEC.
what do you mean with "behaves differently"?
im using ubuntu...
this is a problem that i have to worrie about?
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
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?
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.
thx
Topic archived. No new replies allowed.