"C ++ Performance Tuning Guide"

Optimization is an experimental science, so it is necessary to debug and analysis.

Domain-optimized performance: small embedded devices and mobile devices, large servers, distributed computing and other computing applications with limited resources.

C ++ code optimization strategy Summary:

1. Use good compiler and compiler with good

(1) that supports the C ++ compiler 11, C ++ -std-11,
(2) open compiler optimization options, -O2, but the code debugging process becomes difficult
with the optimization function (3) is opened option, inline
(4) compiler to compile the program performance: INTEL icc> GNU gcc

2. Use a better algorithm

Most optimization methods can enhance the performance of the program 30% -100% or 3 times, but the use of more efficient algorithms can achieve exponential growth performance.
(1) the optimal algorithm of searching and sorting
(2) optimal algorithm specific areas
(3) Tip: Precomputed (calculated from the move to the runtime linker, compiler design or), delay calculation (the calculation of deferred when really need to use the calculation result, before calculation), cache (save and reuse, to reduce unnecessary data swapped out, it is to reduce the bandwidth of the L1 / L2 / L3) of

3. Use a better library

Standard C ++ template library and runtime library must be maintained, comprehensive, very robust, so performance will be a compromise.
Optimization (1) C ++ Standard Template Library
(2) the Boost Project
(3) Google Code
(4) to develop their own libraries, reducing security and robustness constraints, in exchange for faster performance

4. Reduce the memory allocation and copy

Most of the performance overhead of C ++ language features most only a few instructions, but each call to the memory manager is spending thousands of instructions.
(1) optimization of the string
(2) to reduce the performance overhead of dynamic memory allocation
(3) reducing the cache copy function: constructor, assignment operator, the input and output

5. Calculation removed

In addition to memory allocation and function calls, the performance overhead of a single C ++ statement is usually very small.
(1) determine which part of the program is executed frequently hostspot, and then try to reduce the number of calculations

6. better data structure

C ++ Standard Library performance data structure (1) is clear, and weigh the behavior

7. improve concurrency

(1) concurrent execution: synchronization of concurrent threads so that they can share data

8. optimized memory management

(1) dynamic memory allocation management

Guess you like

Origin www.cnblogs.com/qccz123456/p/11537280.html