-28- Code Complete learning strategies and techniques to adjust the code (Code-Tuning Stategies and Techniques)

    Speaking in front of the reconstruction, reconstruction goal is to improve the readability of the code maintainability. The main goal here speak of the code is adjusted for the performance of the software. In many cases, performance, maintainability and readability are conflicting indicators, so before doing code tuning, it must find a good really need? To improve the performance of the software there are many ways, are listed in the following checklist, the code adjustment is a method other methods have had to die before using. In short, caution!
Checklist: Code-the Tuning Strategies,
 Overall Program Performance
  Have you Considered Improving Performance by Changing at The Program requirements?
  Have you Considered Improving Performance by modifying at The Program's Design?
  Have you Considered Improving Performance by modifying at The class Design?
  Have you Considered Improving Performance by Avoiding Operating Interactions System?
  Have you Considered Improving Performance by Avoiding the I / O?
  Have you Considered Improving Performance by a using INSTEAD of AN A Compiled Language Interpreted Language?
  Have you considered improving performance by using compiler optimizations?
  Have you considered improving performance by switching to different hardware?
  Have you considered code tuning only as a last resort?
 Code-Tuning Approach
  Is your program fully correct before you begin code tuning?
  Have you measured performance bottlenecks before beginning code tuning?
  Have you measured the effect of each code-tuning change?
  Have you backed out the code-tuning changes that didn't produce the intended improvement?
  Have you tried more than one change to improve performance of each bottleneck, i.e., iterated?
    It will have reason to exist, since the total in some cases we had to use the code changes, he should know about some of the techniques used in time. The first thing to do is to measure. Good performance is not good, how fast, light-guessing is not enough, we must measure to know; how to adjust the effect, and only measure to know. Therefore, the measure is the first step. According to the famous 80/20 rule, there is always a small part of the code that consumes most of the performance, we need to find that a small part of the code by measuring, then adjust them to optimize.
    We have different methods of adjustment, following checklist are listed, not one by one explain the book are reference examples. It should be noted that no matter which method, because the compiler, the language, the environment is different, the result is often unpredictable, so the results of how to adjust the code must be confirmed by measurement. It is also worth mentioning that the code can be adjusted to optimize multi-pronged approach, as better results. But we must note that the more often optimize readability maintainability worse, this trade-off, to what extent be considered good.
Checklist: Code the Tuning Techniques
 the Improve Size Both Speed and
  Substitute Table Lookups for Complicated Logic
  Jam Loops
  the Use of Floating-Point Integer Variables INSTEAD
  the Initialize Data Time AT the compile
  the Use Constants The correct type of
  the Precompute Results
  the Eliminate Common subexpressions
  Translate key routines to assembler
 Improve Speed Only
  Stop testing when you know the answer
  Order tests in case statements and if-then-else chains by frequency
  Compare performance of similar logic structures
  Use lazy evaluation
  Unswitch loops that contain if tests
  Unroll loops
  Minimize work performed inside loops
  Use sentinels in search loops
  Put the busiest loop on the inside of nested loops
  Reduce the strength of operations performed inside loops
  Change multiple-dimension arrays to a single dimension
  Minimize array references
  Augment data types with indexes
  Cache frequently used values
  Exploit algebraic identities
  Reduce strength in logical and mathematical expressions
  Be wary of system routines
  Rewrite routines in line
Published 63 original articles · won praise 16 · views 30000 +

Guess you like

Origin blog.csdn.net/tyst08/article/details/7983663