5.4 Eliminating loop inefficienciesapp
A general class of optimizations is known as code
motion. They involve identifying a computation that is
performed multiple times,(e.g.,within a loop), but such
that the result of the computation will not change.ide
5.5 Reducing Procedure Callsoop
5.6 Elimiating Unneeded Memory Referencesui
5.13 Performance improvement techniquescode
For optimizing program performance:orm
High-level design:three
Choose appropriate algorithms and data structures.ip
Basic coding principles:ci
+ Eliminate excessive function calls.
+ Eliminate unnecessary memory references. Introduces
temporary varibles to hold intermediate results.it
Low-level optimizations, Structure code to take advan-
tage of the hardware capabilities:
+ Unroll loops to reduce overhead and to enable fur-
ther optimizations.
+ Find ways to increase instruction-level parallelism
by techniques such as multiple accumulators and
reassociation.
+ rewrite conditional operations in a functional
style to enable compilation via conditional data
transfers.
5.14.1 Program profiling
Profiling with GPROF requires three steps:
# -pg to ensure compiler does not do any optimizes. 1. gcc -Og -pg prog.c -o prog 2. executed as usual: ./prog 3. GPROF is invoked to analyze the data in gmon.out gprof prog