Writing C/C++ Code
3-3
Optimizing C/C++ Code
3.1.2
Analyzing C Code Performance
Use the following techniques to analyze the performance of specific code re-
gions:
-
One of the preliminary measures of code is the time it takes the code to
run. Use the clock( ) and printf( ) functions in C/C++ to time and display
the performance of specific code regions. You can use the stand-alone
simulator (load6x) to run the code for this purpose. Remember to subtract
out the overhead of calling the clock( ) function.
-
Use the profile mode of the stand-alone simulator. This can be done by
compiling your code with the –mg option and executing load6x with the –g
option. The profile results will be stored in a file with the .vaa extension.
Refer to the
TMS320C6000 Optimizing C/C++ Compiler User’s Guide for
more information.
-
Enable the clock and use profile points and the RUN command in the Code
Composer debugger to track the number of CPU clock cycles consumed
by a particular section of code. Use “View Statistics” to view the number
of cycles consumed.
-
The critical performance areas in your code are most often loops. The
easiest way to optimize a loop is by extracting it into a separate file that
can be rewritten, recompiled, and run with the stand-alone simulator
(load6x).
As you use the techniques described in this chapter to optimize your C/C++
code, you can then evaluate the performance results by running the code and
looking at the instructions generated by the compiler.