Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 25: Code-Tuning Strategies. Chapter 25  Code tuning is one way of improving a program’s performance, You can often find other ways to improve.

Similar presentations


Presentation on theme: "Chapter 25: Code-Tuning Strategies. Chapter 25  Code tuning is one way of improving a program’s performance, You can often find other ways to improve."— Presentation transcript:

1 Chapter 25: Code-Tuning Strategies

2 Chapter 25  Code tuning is one way of improving a program’s performance, You can often find other ways to improve performance more- and in less time and with less harm to the code-than by code tuning.

3 Performance and Code Tuning  Efficiency as a priority  Program requirements  Program design  Class and routine design  Operating-system interactions  Code compilation  Hardware  Code tuning

4 Program Requirements  Performance is stated as priority more often than it actually is a requirement  Before you invest time solving a performance problem, make sure that you’re solving a problem that needs to be solved.

5 Program Design  Program design includes the major strokes of the design for a single program, mainly the way in which a program is divided into classes.  Some program designs make it difficult to write a high-performance system.

6 Class and Routine Design  Designing the internals of classes and routines presents another opportunity to design for performance.  The choice of data types and algorithms is a performance factor that can effect the program’s memory and execution speed.

7 Code Compilation  Compilers turn clear, high-level language code into optimized machine code.  If you choose the right compiler, you might not need to think about optimizing speed any further.

8 Hardware  Sometimes the cheapest and best way to improve a program’s performance is to buy new hardware.  If you’re developing custom software for a few in-house users, a hardware upgrade might be the cheapest option.

9 Code Tuning  Code tuning is the practice of modifying correct code in ways that make ir run more efficiently.  “Tuning” refers to small-scale changes that affect a single class, a single routine, or more commonly a few lines of code.

10 The Pareto Principle  The Pareto Principle states that you can get 80 percent of the result with 20 percent of the effort.  Jon Bentley describes a case in which a 1000 line program spent 80 percent of its time in a five-line square root routine. By tripling the speed of the square root routine, he doubled the speed of the program.

11 Old Wives’ Tales  Reducing the lines of code in a high-level language improves the speed or size of the resulting machine code.  Examples:  For i=1to 10 a[i] = I End for  A[1] = 1 A[2]=2 ….

12 Old Wives’ Tales  Certain operations are probably faster or smaller than others.  You should optimize as you go.  A fast program is just as important as a correct one.

13 Compiler Optimizations  Shop for a compiler because each compiler can add performance to certain parts of your code.

14 Common Sources of operations  Input/output operations  An operation that causes the operating system to swap pages of memory is much slower than an operation that works on only one page of memory  System calls can eat up a lot of time.  Avoid going to the system

15 Chapter 26: Code-Tuning Techniques

16 Stop Testing When You Know the Answer  negativeInputFound=false; For (…..){ if(input[i]<0){ negativeInputFound=true; }

17 Order Tests by Frequency  Arrange test so that the one that’s fastest and most likely to be true is performed first.  Switch statement.

18 Compare Performance of Similar Logic Structures  Switch statement vs. if statement VS.

19 Use Lazy Evaluation  Some things can wait to be calculated.

20 Jamming  Jamming is the result of combining two loops that operate on the same set of elements.

21 Unrolling  Often more lines of code can be more efficient.

22 Minimizing the Work inside loops  Improving readability  Saving pointers as a well named variable.

23 Putting the Busiest Loop on the inside  When you have nested loops it is better to put the bigger loop on the inside.  It can save time up to 33% in C++

24 Data transformations  Use integers rather than floating –point numbers.  Addition and multiplication of integers is faster then floating point values

25 Arrays  Use the fewest array dimensions as possible  Minimize Array references

26


Download ppt "Chapter 25: Code-Tuning Strategies. Chapter 25  Code tuning is one way of improving a program’s performance, You can often find other ways to improve."

Similar presentations


Ads by Google