LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   measure program performance (https://www.linuxquestions.org/questions/programming-9/measure-program-performance-320042/)

cranium2004 05-04-2005 09:33 AM

measure program performance
 
hello,
If i wrote a C function then how to know that its costlier in terms of processing time,execution,compilation.
I have written 2 functions for one problem but dont understand which one is best from Opereating System's overhead point of view. so i want tool that measure it.
If this is not right place to ask then tell me where to ask in any other forum.

LogicG8 05-04-2005 10:49 AM

Well if you want precise measurements use a profiler like gprof
or oprofile. Otherwise you can get a good idea of the by writing
a simple wrapper program that calls your functions a lot.

Code:

/* Anything your functions need */
#include <limits.h>  /* For ULONG_MAX */

int main(int argc, char *argv[])
{
    for (unsigned long i = 0; i < ULONG_MAX; i++) {
      call_your test_function_here();
    }
    return 0;
}

Then use the time command to measure performance like so
time ./test_func

Warning depending on your function 2^32 or 2^64 (which depends
on your platforms architechture) may take a long time to complete.


All times are GMT -5. The time now is 07:29 PM.