You can start collecting information about your application performance with simply timing your application. More sophisticated and helpful data can be collected by using performance analyzing tools.
One of the performance indicators is your application timing. The following considerations apply to timing your application:
Run program timings when other users are not active. Your timing results can be affected by one or more CPU-intensive processes also running while doing your timings.
Try to run the program under the same conditions each time to provide the most accurate results, especially when comparing execution times of a previous version of the same program. Use the same system (processor model, amount of memory, version of the operating system, and so on) if possible.
If you do need to change systems, you should measure the time using the same version of the program on both systems, so you know each system's effect on your timings.
For programs that run for less than a few seconds, run several timings to ensure that the results are not misleading. Certain overhead functions like loading libraries might influence short timings considerably.
If your program displays a lot of text, consider
redirecting the output from the program. Redirecting output from the program
will change the times reported because of reduced screen I/O.
Timings that show a large amount of system time may indicate a lot
of time spent doing I/O,
which might be worth investigating.
For programs that run for less than a few seconds,
run several timings to ensure that the results are not misleading. Overhead
functions like loading shared libraries might influence short timings
considerably.
Use the time command and
specify the
name of the executable program to provide the following:
The elapsed, real, or "wall clock" time, which will be greater than the total charged actual CPU time.
Charged actual CPU time, shown for both system and user execution. The total actual CPU time is the sum of the actual user CPU time and actual system CPU time.
The following program illustrates a model for program timing:
Example |
---|
/* Sample Timing */ #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { clock_t start, finish; long loop; double duration, loop_calc; start = clock(); for(loop=0; loop <= 2000; loop++) { loop_calc = 123.456 * 789; //printf() included to facilitate example printf("\nThe value of loop is: %d", loop); } finish = clock(); duration = (double)(finish - start)/CLOCKS_PER_SEC; printf("\n%2.3f seconds\n", duration); } |